aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/IO
diff options
context:
space:
mode:
authorebr11 Eric Reed spam <ebr11 Eric Reed spam@reedsplace.com>2012-09-20 11:25:16 -0400
committerebr11 Eric Reed spam <ebr11 Eric Reed spam@reedsplace.com>2012-09-20 11:25:16 -0400
commit4e3ce41880d643a2951dc971f1e8f6e21f57829c (patch)
treefb2efff3008e69627e843289fa1932663e40bbf5 /MediaBrowser.Controller/IO
parent6edc836ce591c466743a1d94a75cb3537c4835bd (diff)
Some directory-watcher rework - still not working properly
Diffstat (limited to 'MediaBrowser.Controller/IO')
-rw-r--r--MediaBrowser.Controller/IO/DirectoryWatchers.cs44
1 files changed, 32 insertions, 12 deletions
diff --git a/MediaBrowser.Controller/IO/DirectoryWatchers.cs b/MediaBrowser.Controller/IO/DirectoryWatchers.cs
index 8243c8174..2e3340089 100644
--- a/MediaBrowser.Controller/IO/DirectoryWatchers.cs
+++ b/MediaBrowser.Controller/IO/DirectoryWatchers.cs
@@ -16,7 +16,7 @@ namespace MediaBrowser.Controller.IO
private Timer updateTimer;
private List<string> affectedPaths = new List<string>();
- private const int TimerDelayInSeconds = 5;
+ private const int TimerDelayInSeconds = 30;
public void Start()
{
@@ -44,12 +44,13 @@ namespace MediaBrowser.Controller.IO
var watcher = new FileSystemWatcher(path, "*") { };
watcher.IncludeSubdirectories = true;
- watcher.Changed += watcher_Changed;
+ //watcher.Changed += watcher_Changed;
// All the others seem to trigger change events on the parent, so let's keep it simple for now.
- //watcher.Created += watcher_Changed;
- //watcher.Deleted += watcher_Changed;
- //watcher.Renamed += watcher_Changed;
+ // Actually, we really need to only watch created, deleted and renamed as changed fires too much -ebr
+ watcher.Created += watcher_Changed;
+ watcher.Deleted += watcher_Changed;
+ watcher.Renamed += watcher_Changed;
watcher.EnableRaisingEvents = true;
FileSystemWatchers.Add(watcher);
@@ -58,9 +59,23 @@ namespace MediaBrowser.Controller.IO
void watcher_Changed(object sender, FileSystemEventArgs e)
{
- if (!affectedPaths.Contains(e.FullPath))
+ Logger.LogDebugInfo("****** Watcher sees change of type " + e.ChangeType.ToString() + " to " + e.FullPath);
+ lock (affectedPaths)
{
- affectedPaths.Add(e.FullPath);
+ if (!affectedPaths.Contains(e.FullPath))
+ {
+ Logger.LogDebugInfo("****** Adding " + e.FullPath + " to affected paths.");
+ affectedPaths.Add(e.FullPath);
+ }
+ if (e.ChangeType == WatcherChangeTypes.Renamed)
+ {
+ var renamedArgs = e as RenamedEventArgs;
+ if (affectedPaths.Contains(renamedArgs.OldFullPath))
+ {
+ Logger.LogDebugInfo("****** Removing " + renamedArgs.OldFullPath + " from affected paths.");
+ affectedPaths.Remove(renamedArgs.OldFullPath);
+ }
+ }
}
if (updateTimer == null)
@@ -77,9 +92,12 @@ namespace MediaBrowser.Controller.IO
{
updateTimer.Dispose();
updateTimer = null;
-
- List<string> paths = affectedPaths;
- affectedPaths = new List<string>();
+ List<string> paths;
+ lock (affectedPaths)
+ {
+ paths = affectedPaths;
+ affectedPaths = new List<string>();
+ }
await ProcessPathChanges(paths).ConfigureAwait(false);
}
@@ -106,14 +124,16 @@ namespace MediaBrowser.Controller.IO
return Kernel.Instance.ReloadRoot();
}
- return Task.WhenAll(itemsToRefresh.Select(i => Kernel.Instance.ReloadItem(i)));
+ foreach (var p in paths) Logger.LogDebugInfo("********* "+ p + " reports change.");
+ foreach (var i in itemsToRefresh) Logger.LogDebugInfo("********* "+i.Name + " will be refreshed.");
+ return Task.WhenAll(itemsToRefresh.Select(i => i.ChangedExternally()));
}
private BaseItem GetAffectedBaseItem(string path)
{
BaseItem item = null;
- while (item == null)
+ while (item == null && !string.IsNullOrEmpty(path))
{
item = Kernel.Instance.RootFolder.FindByPath(path);