diff --git a/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs b/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs
index 61ae13580cea7..312e600b05399 100644
--- a/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs
+++ b/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs
@@ -340,15 +340,6 @@ private void OnFileSystemEntryChange(string fullPath)
{
try
{
- // this can happen when the fullPath matches the root directory path
- // but the root path is always created with a trailing slash
- // this was masked by a side effect (bug) in RenamedEventArgs that was appending the trailing slash to fullPath value
- // that behavior was changed with the fix for https://github.com/dotnet/runtime/issues/62606
- if (fullPath.Length < _root.Length)
- {
- return;
- }
-
var fileSystemInfo = new FileInfo(fullPath);
if (FileSystemInfoHelper.IsExcluded(fileSystemInfo, _filters))
{
diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj b/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
index c813f682fa406..591fd42da884b 100644
--- a/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
+++ b/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
@@ -25,10 +25,12 @@
-
-
+
+
+
diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/RenamedEventArgs.cs b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/RenamedEventArgs.cs
index 88da14883a7ee..72dc9765f05fb 100644
--- a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/RenamedEventArgs.cs
+++ b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/RenamedEventArgs.cs
@@ -19,6 +19,11 @@ public RenamedEventArgs(WatcherChangeTypes changeType, string directory, string?
{
_oldName = oldName;
_oldFullPath = Path.Join(Path.GetFullPath(directory), oldName);
+
+ if (string.IsNullOrWhiteSpace(oldName))
+ {
+ _oldFullPath = PathInternal.EnsureTrailingSeparator(_oldFullPath);
+ }
}
///
diff --git a/src/libraries/System.IO.FileSystem.Watcher/tests/Args.FileSystemEventArgs.cs b/src/libraries/System.IO.FileSystem.Watcher/tests/Args.FileSystemEventArgs.cs
index 727d48d74689f..eb655aedb450e 100644
--- a/src/libraries/System.IO.FileSystem.Watcher/tests/Args.FileSystemEventArgs.cs
+++ b/src/libraries/System.IO.FileSystem.Watcher/tests/Args.FileSystemEventArgs.cs
@@ -81,10 +81,12 @@ public static void FileSystemEventArgs_ctor_RelativePathFromCurrentDirectoryInGi
[Theory]
[InlineData("bar", "")]
[InlineData("bar", null)]
- public static void FileSystemEventArgs_ctor_When_EmptyFileName_Then_FullPathReturnsTheDirectoryFullPath(string directory, string name)
+ public static void FileSystemEventArgs_ctor_When_EmptyFileName_Then_FullPathReturnsTheDirectoryFullPath_WithTrailingSeparator(string directory, string name)
{
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);
+ directory = PathInternal.EnsureTrailingSeparator(directory);
+
Assert.Equal(PathInternal.EnsureTrailingSeparator(Directory.GetCurrentDirectory()) + directory, args.FullPath);
}
diff --git a/src/libraries/System.IO.FileSystem.Watcher/tests/Args.RenamedEventArgs.cs b/src/libraries/System.IO.FileSystem.Watcher/tests/Args.RenamedEventArgs.cs
index f1f7ce82b6e5c..f1421cc15ecb0 100644
--- a/src/libraries/System.IO.FileSystem.Watcher/tests/Args.RenamedEventArgs.cs
+++ b/src/libraries/System.IO.FileSystem.Watcher/tests/Args.RenamedEventArgs.cs
@@ -31,8 +31,6 @@ public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsAnAbsolutePath_W
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);
Assert.Equal(expectedOldFullPath, args.OldFullPath);
- Assert.Equal(name, args.Name);
- Assert.Equal(oldName, args.OldName);
}
[Theory]
@@ -86,10 +84,12 @@ public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsRelativePathFrom
[InlineData( "bar", "", "")]
[InlineData( "bar", null, null)]
[InlineData( "bar", "foo.txt", null)]
- public static void RenamedEventArgs_ctor_When_EmptyOldFileName_Then_OldFullPathReturnsTheDirectoryFullPath(string directory, string name, string oldName)
+ public static void RenamedEventArgs_ctor_When_EmptyOldFileName_Then_OldFullPathReturnsTheDirectoryFullPath_WithTrailingSeparator(string directory, string name, string oldName)
{
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);
+ directory = PathInternal.EnsureTrailingSeparator(directory);
+
Assert.Equal(PathInternal.EnsureTrailingSeparator(Directory.GetCurrentDirectory()) + directory, args.OldFullPath);
}