Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSteve Pfister <steveisok@users.noreply.github.com>2019-07-02 18:52:40 +0300
committerMarek Safar <marek.safar@gmail.com>2019-07-02 18:52:40 +0300
commitcdab3b687ac7a23dbb95e7b9f6d18bec12cae443 (patch)
tree4447a165d8c56551f4bd81746505bd78c553f9e5 /src
parentb7a9aef96775f1d2d5a4ffb59ad691dc3b67d005 (diff)
Add Empty Path Check to the Start of FileSystemWatcher Notify Events (#305)
* Fixes https://github.com/mono/mono/issues/15434 by checking if the path is effectively empty before interacting with any Path methods. We needed to modify the fork at this point because Mono still supports netfx Path rules, which cannot contain spaces (CoreFX allows this on nix). * Review tweaks
Diffstat (limited to 'src')
-rw-r--r--src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs18
-rw-r--r--src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs19
2 files changed, 37 insertions, 0 deletions
diff --git a/src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs b/src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs
index 930816c553..45df8be254 100644
--- a/src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs
+++ b/src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs
@@ -391,12 +391,30 @@ namespace System.IO
throw new ArgumentException(SR.Format(SR.InvalidDirName_NotExists, path), nameof(path));
}
+#if MONO
+ /// <summary>
+ /// Returns true if the path is effectively empty for the current OS.
+ /// This function is borrowed from PathInternal.Windows because Mono
+ /// on the desktop still needs to support the netfx behavior.
+ /// EffectivelyEmpty means an empty span, null, or just spaces ((char)32).
+ /// </summary>
+ private static bool IsEffectivelyEmpty(ReadOnlySpan<char> path)
+ {
+ return (path.IsEmpty || path.IndexOf(' ') > -1);
+ }
+#endif
+
/// <summary>
/// Sees if the name given matches the name filter we have.
/// </summary>
private bool MatchPattern(ReadOnlySpan<char> relativePath)
{
+#if MONO
+ if (IsEffectivelyEmpty (relativePath))
+ return false;
+#endif
ReadOnlySpan<char> name = IO.Path.GetFileName(relativePath);
+
if (name.Length == 0)
return false;
diff --git a/src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs b/src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs
index 5035709528..003a54c9e4 100644
--- a/src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs
+++ b/src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs
@@ -637,5 +637,24 @@ namespace System.IO.Tests
}
}
}
+
+#if MONO && (!MOBILE || MOBILE_DESKTOP_HOST)
+ [Fact]
+ [PlatformSpecific(TestPlatforms.AnyUnix)]
+ public void FileSystemWatcher_WatchFileWithSpaces()
+ {
+ using (var testDirectory = new TempDirectory(GetTestFilePath()))
+ using (var file = new TempFile(Path.Combine(testDirectory.Path, " ")))
+ using (var watcher = new FileSystemWatcher(testDirectory.Path, "*"))
+ {
+ NotifyFilters filter = NotifyFilters.LastWrite | NotifyFilters.FileName;
+ watcher.NotifyFilter = filter;
+
+ Action action = () => File.AppendAllText(file.Path, "longText!");
+
+ ExpectNoEvent(watcher, WatcherChangeTypes.Changed, action, expectedPath: file.Path);
+ }
+ }
+#endif
}
}