Fixing dotnet/corefx#2279 to make the Linux FSW ignore root folder changes

Commit migrated from https://github.com/dotnet/corefx/commit/777e88a068c9e7509fd56bfcce20fbfe52f687f7
This commit is contained in:
Jon Miller authored and Jonathan Miller committed 2016-02-11 15:05:00 -08:00
1 parent 080287c216
commit ea00cd6975
2 files changed
+25

No files matched your search

@@ -572,6 +572,13 @@ namespace System.IO
expandedName = associatedDirectoryEntry.GetPath(true, nextEvent.name);
}
// To match Windows, ignore all changes that happen on the root folder itself
if (string.IsNullOrEmpty(expandedName))
{
watcher = null;
continue;
}
// Determine whether the affected object is a directory (rather than a file).
// If it is, we may need to do special processing, such as adding a watch for new
// directories if IncludeSubdirectories is enabled. Since we're only watching
@@ -250,4 +250,22 @@ public class ChangedTests
Utility.ExpectNoEvent(are, "symlink'd file change");
}
}
[Fact]
public static void FileSystemWatcher_Changed_RootFolderChangeDoesNotFireEvent()
{
using (var dir = Utility.CreateTestDirectory())
using (var watcher = new FileSystemWatcher())
{
AutoResetEvent are = Utility.WatchForEvents(watcher, WatcherChangeTypes.Changed);
// Setup the watcher
watcher.Path = Path.GetFullPath(dir.Path);
watcher.Filter = "*";
watcher.EnableRaisingEvents = true;
Directory.SetLastWriteTime(dir.Path, DateTime.Now.AddSeconds(10));
Utility.ExpectNoEvent(are, "Root Directory Change");
}
}
}