diff options
| author | ebr11 Eric Reed spam <ebr11 Eric Reed spam@reedsplace.com> | 2012-09-20 13:53:10 -0400 |
|---|---|---|
| committer | ebr11 Eric Reed spam <ebr11 Eric Reed spam@reedsplace.com> | 2012-09-20 13:53:10 -0400 |
| commit | da618f13e23cbef6ca71c8c0099dfd563a394fa5 (patch) | |
| tree | 5492e605c56fcd5bf608e3becf597a258c5ed9c7 | |
| parent | ef07c2e6ab71552b088dc223666a18167ca31182 (diff) | |
Fix up directory watchers
| -rw-r--r-- | MediaBrowser.Common/Extensions/BaseExtensions.cs | 6 | ||||
| -rw-r--r-- | MediaBrowser.Controller/IO/DirectoryWatchers.cs | 19 |
2 files changed, 17 insertions, 8 deletions
diff --git a/MediaBrowser.Common/Extensions/BaseExtensions.cs b/MediaBrowser.Common/Extensions/BaseExtensions.cs index 10ff019aa..77eb9fbb4 100644 --- a/MediaBrowser.Common/Extensions/BaseExtensions.cs +++ b/MediaBrowser.Common/Extensions/BaseExtensions.cs @@ -28,11 +28,13 @@ namespace MediaBrowser.Common.Extensions /// <returns></returns>
public static bool ContainsParentFolder(this List<string> lst, string path)
{
+ path = path.TrimEnd('\\');
foreach (var str in lst)
{
//this should be a little quicker than examining each actual parent folder...
- if (path.Equals(str,StringComparison.OrdinalIgnoreCase)
- || (path.StartsWith(str, StringComparison.OrdinalIgnoreCase) && path[str.Length-1] == '\\')) return true;
+ var compare = str.TrimEnd('\\');
+ if (path.Equals(compare,StringComparison.OrdinalIgnoreCase)
+ || (path.StartsWith(compare, StringComparison.OrdinalIgnoreCase) && path[compare.Length] == '\\')) return true;
}
return false;
}
diff --git a/MediaBrowser.Controller/IO/DirectoryWatchers.cs b/MediaBrowser.Controller/IO/DirectoryWatchers.cs index 2e3340089..eb1358e16 100644 --- a/MediaBrowser.Controller/IO/DirectoryWatchers.cs +++ b/MediaBrowser.Controller/IO/DirectoryWatchers.cs @@ -62,11 +62,9 @@ namespace MediaBrowser.Controller.IO Logger.LogDebugInfo("****** Watcher sees change of type " + e.ChangeType.ToString() + " to " + e.FullPath);
lock (affectedPaths)
{
- if (!affectedPaths.Contains(e.FullPath))
- {
- Logger.LogDebugInfo("****** Adding " + e.FullPath + " to affected paths.");
- affectedPaths.Add(e.FullPath);
- }
+ //Since we're watching created, deleted and renamed we always want the parent of the item to be the affected path
+ var affectedPath = Path.GetDirectoryName(e.FullPath);
+
if (e.ChangeType == WatcherChangeTypes.Renamed)
{
var renamedArgs = e as RenamedEventArgs;
@@ -76,6 +74,15 @@ namespace MediaBrowser.Controller.IO affectedPaths.Remove(renamedArgs.OldFullPath);
}
}
+
+ //If anything underneath this path was already marked as affected - remove it as it will now get captured by this one
+ affectedPaths.RemoveAll(p => p.StartsWith(e.FullPath, StringComparison.OrdinalIgnoreCase));
+
+ if (!affectedPaths.ContainsParentFolder(affectedPath))
+ {
+ Logger.LogDebugInfo("****** Adding " + affectedPath + " to affected paths.");
+ affectedPaths.Add(affectedPath);
+ }
}
if (updateTimer == null)
@@ -125,7 +132,7 @@ namespace MediaBrowser.Controller.IO }
foreach (var p in paths) Logger.LogDebugInfo("********* "+ p + " reports change.");
- foreach (var i in itemsToRefresh) Logger.LogDebugInfo("********* "+i.Name + " will be refreshed.");
+ foreach (var i in itemsToRefresh) Logger.LogDebugInfo("********* "+i.Name + " ("+ i.Path + ") will be refreshed.");
return Task.WhenAll(itemsToRefresh.Select(i => i.ChangedExternally()));
}
|
