handle path stripping correctly for root of watched tree
authorDaniel Becker <razzfazz@gmail.com>
Sat, 9 Jan 2016 19:53:54 +0000 (11:53 -0800)
committerDaniel Becker <razzfazz@gmail.com>
Sat, 9 Jan 2016 20:28:33 +0000 (12:28 -0800)
mcs/class/System/System.IO/KeventWatcher.cs

index 996e0e9b61fafdaf6fa845d870a1e19b7a372ff5..6875dbdc476ba75d94cb00d9c93aeef7c45295b2 100644 (file)
@@ -606,14 +606,14 @@ namespace System.IO {
                                return;
 
                        // e.Name
-                       string name = path.Substring (fullPathNoLastSlash.Length + 1); 
+                       string name = (path.Length > fullPathNoLastSlash.Length) ? path.Substring (fullPathNoLastSlash.Length + 1) : String.Empty;
 
                        // only post events that match filter pattern. check both old and new paths for renames
                        if (!fsw.Pattern.IsMatch (path) && (newPath == null || !fsw.Pattern.IsMatch (newPath)))
                                return;
                                
                        if (action == FileAction.RenamedNewName) {
-                               string newName = newPath.Substring (fullPathNoLastSlash.Length + 1);
+                               string newName = (newPath.Length > fullPathNoLastSlash.Length) ? newPath.Substring (fullPathNoLastSlash.Length + 1) : String.Empty;
                                renamed = new RenamedEventArgs (WatcherChangeTypes.Renamed, fsw.Path, newName, name);
                        }