Skip to content

Commit befe6f1

Browse files
niklaskallanderxavierdecoster
authored andcommitted
Adds a new app setting (enableFileSystemMonitoring:bool) (#19)
* Adds a new app setting (enableFileSystemMonitoring:bool) to specify whether file system monitoring should be enabled for the nuget server * Explanatory note about consequences of disabling file system monitoring
1 parent 6bc986b commit befe6f1

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/NuGet.Server/Infrastructure/ServerPackageRepository.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ public void ClearCache()
569569

570570
private void MonitorFileSystem(bool monitor)
571571
{
572-
if (!_runBackgroundTasks)
572+
if (!EnableFileSystemMonitoring || !_runBackgroundTasks)
573573
{
574574
return;
575575
}
@@ -599,7 +599,7 @@ private void MonitorFileSystem(bool monitor)
599599
private void RegisterFileSystemWatcher()
600600
{
601601
// When files are moved around, recreate the package cache
602-
if (_runBackgroundTasks && _fileSystemWatcher == null && !string.IsNullOrEmpty(Source) && Directory.Exists(Source))
602+
if (EnableFileSystemMonitoring && _runBackgroundTasks && _fileSystemWatcher == null && !string.IsNullOrEmpty(Source) && Directory.Exists(Source))
603603
{
604604
// ReSharper disable once UseObjectOrCollectionInitializer
605605
_fileSystemWatcher = new FileSystemWatcher(Source);
@@ -694,7 +694,16 @@ private bool EnableFrameworkFiltering
694694
return _getSetting("enableFrameworkFiltering", false);
695695
}
696696
}
697-
697+
698+
private bool EnableFileSystemMonitoring
699+
{
700+
get
701+
{
702+
// If the setting is misconfigured, treat it as on (backwards compatibility).
703+
return _getSetting("enableFileSystemMonitoring", true);
704+
}
705+
}
706+
698707
private static bool GetBooleanAppSetting(string key, bool defaultValue)
699708
{
700709
var appSettings = WebConfigurationManager.AppSettings;

src/NuGet.Server/Web.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@
4949
Uncomment the following configuration entry to enable NAT support.
5050
-->
5151
<!-- <add key="aspnet:UseHostHeaderForRequestUrl" value="true" /> -->
52+
<!--
53+
Set enableFileSystemMonitoring to true (default) to enable file system monitoring (which will update the package cache appropriately on file system changes).
54+
Set it to false to disable file system monitoring.
55+
NOTE: Disabling file system monitoring may result in increased storage capacity requirements as package cache may only be purged by a background job running
56+
on a fixed 1-hour interval.
57+
-->
58+
<add key="enableFileSystemMonitoring" value="true" />
5259
</appSettings>
5360
<!--
5461
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

0 commit comments

Comments
 (0)