Fixed possible race condition.
This commit is contained in:
parent
406aea6ead
commit
f06b04ede4
@ -75,6 +75,8 @@ namespace FileManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateLocalCache(FileSystemEventArgs change)
|
private void UpdateLocalCache(FileSystemEventArgs change)
|
||||||
|
{
|
||||||
|
lock (fsCache)
|
||||||
{
|
{
|
||||||
if (change.ChangeType == WatcherChangeTypes.Deleted)
|
if (change.ChangeType == WatcherChangeTypes.Deleted)
|
||||||
{
|
{
|
||||||
@ -92,28 +94,23 @@ namespace FileManager
|
|||||||
AddPath(renameChange.FullPath);
|
AddPath(renameChange.FullPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void RemovePath(string path)
|
private void RemovePath(string path)
|
||||||
{
|
|
||||||
lock (fsCache)
|
|
||||||
{
|
{
|
||||||
var pathsToRemove = fsCache.Where(p => p.StartsWith(path)).ToArray();
|
var pathsToRemove = fsCache.Where(p => p.StartsWith(path)).ToArray();
|
||||||
|
|
||||||
foreach (var p in pathsToRemove)
|
foreach (var p in pathsToRemove)
|
||||||
fsCache.Remove(p);
|
fsCache.Remove(p);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void AddPath(string path)
|
private void AddPath(string path)
|
||||||
{
|
|
||||||
lock (fsCache)
|
|
||||||
{
|
{
|
||||||
if (File.GetAttributes(path).HasFlag(FileAttributes.Directory))
|
if (File.GetAttributes(path).HasFlag(FileAttributes.Directory))
|
||||||
fsCache.AddRange(Directory.EnumerateFiles(path, SearchPattern, SearchOption));
|
fsCache.AddRange(Directory.EnumerateFiles(path, SearchPattern, SearchOption));
|
||||||
else
|
else
|
||||||
fsCache.Add(path);
|
fsCache.Add(path);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user