aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/IO
diff options
context:
space:
mode:
authortikuf <admin@nyalindee.com>2014-03-29 21:34:16 +1100
committertikuf <admin@nyalindee.com>2014-03-29 21:34:16 +1100
commit241be6dd93f6e0ec96ef88f0182b8985eb275995 (patch)
treeac42c23908911099ebc2840bc6b9549de565bab6 /MediaBrowser.Server.Implementations/IO
parent520b77a098a5f3755c098636821a7ff3742a055f (diff)
parent5e5b1f180c2a13152c8f318f045547c6508c5b3e (diff)
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Diffstat (limited to 'MediaBrowser.Server.Implementations/IO')
-rw-r--r--MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs58
1 files changed, 28 insertions, 30 deletions
diff --git a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs
index 0a0b3f4bc..9279fd8d7 100644
--- a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs
+++ b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs
@@ -249,17 +249,24 @@ namespace MediaBrowser.Server.Implementations.IO
// Creating a FileSystemWatcher over the LAN can take hundreds of milliseconds, so wrap it in a Task to do them all in parallel
Task.Run(() =>
{
- var newWatcher = new FileSystemWatcher(path, "*") { IncludeSubdirectories = true, InternalBufferSize = 32767 };
+ try
+ {
+ var newWatcher = new FileSystemWatcher(path, "*")
+ {
+ IncludeSubdirectories = true,
+ InternalBufferSize = 32767
+ };
- newWatcher.Created += watcher_Changed;
- newWatcher.Deleted += watcher_Changed;
- newWatcher.Renamed += watcher_Changed;
- newWatcher.Changed += watcher_Changed;
+ newWatcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName |
+ NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size;
- newWatcher.Error += watcher_Error;
+ newWatcher.Created += watcher_Changed;
+ newWatcher.Deleted += watcher_Changed;
+ newWatcher.Renamed += watcher_Changed;
+ newWatcher.Changed += watcher_Changed;
+
+ newWatcher.Error += watcher_Error;
- try
- {
if (_fileSystemWatchers.TryAdd(path, newWatcher))
{
newWatcher.EnableRaisingEvents = true;
@@ -272,11 +279,7 @@ namespace MediaBrowser.Server.Implementations.IO
}
}
- catch (IOException ex)
- {
- Logger.ErrorException("Error watching path: {0}", ex, path);
- }
- catch (PlatformNotSupportedException ex)
+ catch (Exception ex)
{
Logger.ErrorException("Error watching path: {0}", ex, path);
}
@@ -346,7 +349,9 @@ namespace MediaBrowser.Server.Implementations.IO
{
try
{
- OnWatcherChanged(e);
+ Logger.Debug("Watcher sees change of type " + e.ChangeType + " to " + e.FullPath);
+
+ ReportFileSystemChanged(e.FullPath);
}
catch (Exception ex)
{
@@ -354,13 +359,6 @@ namespace MediaBrowser.Server.Implementations.IO
}
}
- private void OnWatcherChanged(FileSystemEventArgs e)
- {
- Logger.Debug("Watcher sees change of type " + e.ChangeType + " to " + e.FullPath);
-
- ReportFileSystemChanged(e.FullPath);
- }
-
public void ReportFileSystemChanged(string path)
{
if (string.IsNullOrEmpty(path))
@@ -370,12 +368,9 @@ namespace MediaBrowser.Server.Implementations.IO
var filename = Path.GetFileName(path);
- // Ignore certain files
- if (!string.IsNullOrEmpty(filename) && _alwaysIgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase))
- {
- return;
- }
+ var monitorPath = !(!string.IsNullOrEmpty(filename) && _alwaysIgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase));
+ // Ignore certain files
var tempIgnorePaths = _tempIgnoredPaths.Keys.ToList();
// If the parent of an ignored path has a change event, ignore that too
@@ -416,12 +411,15 @@ namespace MediaBrowser.Server.Implementations.IO
}))
{
- return;
+ monitorPath = false;
}
- // Avoid implicitly captured closure
- var affectedPath = path;
- _affectedPaths.AddOrUpdate(path, path, (key, oldValue) => affectedPath);
+ if (monitorPath)
+ {
+ // Avoid implicitly captured closure
+ var affectedPath = path;
+ _affectedPaths.AddOrUpdate(path, path, (key, oldValue) => affectedPath);
+ }
lock (_timerLock)
{