Skip to content

Commit

Permalink
Keeping the old behavior with trailing separator
Browse files Browse the repository at this point in the history
Reverted the changes to PhysicalFilesWatcher
and added back the trailing separator behavior
as per code review suggestion

Fix dotnet#62606
  • Loading branch information
slask committed Jan 18, 2022
1 parent 5ff61d5 commit aaf4b45
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
<Compile Include="System\IO\WaitForChangedResult.cs" />
<Compile Include="$(CommonPath)System\IO\PathInternal.CaseSensitivity.cs"
Link="Common\System\IO\PathInternal.CaseSensitivity.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsWindows)' == 'true'">
<Compile Include="$(CommonPath)System\IO\PathInternal.cs"
Link="Common\System\IO\PathInternal.cs" />
<Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
Link="Common\System\Text\ValueStringBuilder.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsWindows)' == 'true'">
<Compile Include="$(CommonPath)System\IO\PathInternal.Windows.cs"
Link="Common\System\IO\PathInternal.Windows.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public FileSystemEventArgs(WatcherChangeTypes changeType, string directory, stri
_changeType = changeType;
_name = name;
_fullPath = Path.Join(Path.GetFullPath(directory), name);

if (string.IsNullOrWhiteSpace(name))
{
_fullPath = PathInternal.EnsureTrailingSeparator(_fullPath);
}
}

/// <devdoc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/// <devdoc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit aaf4b45

Please sign in to comment.