Skip to content

Commit 04a7fc5

Browse files
committed
Revert daec9dc (PR dotnet#68582)
1 parent 15d8c86 commit 04a7fc5

4 files changed

Lines changed: 12 additions & 45 deletions

File tree

src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemEventArgs.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,14 @@ public class FileSystemEventArgs : EventArgs
1717
/// </devdoc>
1818
public FileSystemEventArgs(WatcherChangeTypes changeType, string directory, string? name)
1919
{
20-
ArgumentNullException.ThrowIfNull(directory);
21-
2220
_changeType = changeType;
2321
_name = name;
22+
_fullPath = Path.Join(Path.GetFullPath(directory), name);
2423

25-
if (directory.Length == 0) // empty directory means current working dir
24+
if (string.IsNullOrWhiteSpace(name))
2625
{
27-
directory = ".";
26+
_fullPath = PathInternal.EnsureTrailingSeparator(_fullPath);
2827
}
29-
30-
string fullDirectoryPath = Path.GetFullPath(directory);
31-
_fullPath = string.IsNullOrEmpty(name) ? PathInternal.EnsureTrailingSeparator(fullDirectoryPath) : Path.Join(fullDirectoryPath, name);
3228
}
3329

3430
/// <devdoc>

src/libraries/System.IO.FileSystem.Watcher/src/System/IO/RenamedEventArgs.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ public RenamedEventArgs(WatcherChangeTypes changeType, string directory, string?
1818
: base(changeType, directory, name)
1919
{
2020
_oldName = oldName;
21+
_oldFullPath = Path.Join(Path.GetFullPath(directory), oldName);
2122

22-
if (directory.Length == 0) // empty directory means current working dir
23+
if (string.IsNullOrWhiteSpace(oldName))
2324
{
24-
directory = ".";
25+
_oldFullPath = PathInternal.EnsureTrailingSeparator(_oldFullPath);
2526
}
26-
27-
string fullDirectoryPath = Path.GetFullPath(directory);
28-
_oldFullPath = string.IsNullOrEmpty(oldName) ? PathInternal.EnsureTrailingSeparator(fullDirectoryPath) : Path.Join(fullDirectoryPath, oldName);
2927
}
3028

3129
/// <devdoc>

src/libraries/System.IO.FileSystem.Watcher/tests/Args.FileSystemEventArgs.cs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,8 @@ public static void FileSystemEventArgs_ctor_NonPathPropertiesAreSetCorrectly(Wat
2222

2323
[Theory]
2424
[PlatformSpecific(TestPlatforms.Windows)]
25-
[InlineData("D:\\", null, "D:\\")]
26-
[InlineData("D:\\", "", "D:\\")]
2725
[InlineData("D:\\", "foo.txt", "D:\\foo.txt")]
28-
[InlineData("E:\\bar", null, "E:\\bar\\")]
29-
[InlineData("E:\\bar", "", "E:\\bar\\")]
3026
[InlineData("E:\\bar", "foo.txt", "E:\\bar\\foo.txt")]
31-
[InlineData("E:\\bar\\", null, "E:\\bar\\")]
32-
[InlineData("E:\\bar\\", "", "E:\\bar\\")]
33-
[InlineData("E:\\bar\\", "foo.txt", "E:\\bar\\foo.txt")]
3427
public static void FileSystemEventArgs_ctor_DirectoryIsAbsolutePath_Windows(string directory, string name, string expectedFullPath)
3528
{
3629
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);
@@ -40,16 +33,8 @@ public static void FileSystemEventArgs_ctor_DirectoryIsAbsolutePath_Windows(stri
4033

4134
[Theory]
4235
[PlatformSpecific(TestPlatforms.AnyUnix)]
43-
[InlineData("/", null, "/")]
44-
[InlineData("/", "", "/")]
45-
[InlineData("/", " ", "/ ")]
4636
[InlineData("/", "foo.txt", "/foo.txt")]
47-
[InlineData("/bar", null, "/bar/")]
48-
[InlineData("/bar", "", "/bar/")]
4937
[InlineData("/bar", "foo.txt", "/bar/foo.txt")]
50-
[InlineData("/bar/", null, "/bar/")]
51-
[InlineData("/bar/", "", "/bar/")]
52-
[InlineData("/bar/", "foo.txt", "/bar/foo.txt")]
5338
public static void FileSystemEventArgs_ctor_DirectoryIsAbsolutePath_Unix(string directory, string name, string expectedFullPath)
5439
{
5540
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);
@@ -59,32 +44,24 @@ public static void FileSystemEventArgs_ctor_DirectoryIsAbsolutePath_Unix(string
5944

6045
[Theory]
6146
[PlatformSpecific(TestPlatforms.Windows)]
62-
[InlineData("", "")]
63-
[InlineData("", "foo.txt")]
6447
[InlineData("bar", "foo.txt")]
6548
[InlineData("bar\\baz", "foo.txt")]
6649
public static void FileSystemEventArgs_ctor_DirectoryIsRelativePath_Windows(string directory, string name)
6750
{
6851
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);
6952

70-
var expectedDirectory = PathInternal.EnsureTrailingSeparator(Path.Combine(Directory.GetCurrentDirectory(), directory));
71-
Assert.Equal(Path.Combine(expectedDirectory, name), args.FullPath);
53+
Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), directory, name), args.FullPath);
7254
}
7355

7456
[Theory]
7557
[PlatformSpecific(TestPlatforms.AnyUnix)]
76-
[InlineData("", "")]
77-
[InlineData("", "foo.txt")]
78-
[InlineData(" ", " ")]
79-
[InlineData(" ", "foo.txt")]
8058
[InlineData("bar", "foo.txt")]
8159
[InlineData("bar/baz", "foo.txt")]
8260
public static void FileSystemEventArgs_ctor_DirectoryIsRelativePath_Unix(string directory, string name)
8361
{
8462
FileSystemEventArgs args = new FileSystemEventArgs(WatcherChangeTypes.All, directory, name);
8563

86-
var expectedDirectory = PathInternal.EnsureTrailingSeparator(Path.Combine(Directory.GetCurrentDirectory(), directory));
87-
Assert.Equal(Path.Combine(expectedDirectory, name), args.FullPath);
64+
Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), directory, name), args.FullPath);
8865
}
8966

9067
[Theory]
@@ -103,6 +80,7 @@ public static void FileSystemEventArgs_ctor_When_EmptyFileName_Then_FullPathRetu
10380
public static void FileSystemEventArgs_ctor_Invalid()
10481
{
10582
Assert.Throws<ArgumentNullException>(() => new FileSystemEventArgs((WatcherChangeTypes)0, null, "foo.txt"));
83+
Assert.Throws<ArgumentException>(() => new FileSystemEventArgs((WatcherChangeTypes)0, "", "foo.txt"));
10684
}
10785
}
10886
}

src/libraries/System.IO.FileSystem.Watcher/tests/Args.RenamedEventArgs.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,24 @@ public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsAnAbsolutePath_U
4747

4848
[Theory]
4949
[PlatformSpecific(TestPlatforms.Windows)]
50-
[InlineData("", "", "")]
51-
[InlineData("", "foo.txt", "bar.txt")]
5250
[InlineData("bar", "foo.txt", "bar.txt")]
5351
[InlineData("bar\\baz", "foo.txt", "bar.txt")]
5452
public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsRelativePath_Windows(string directory, string name, string oldName)
5553
{
5654
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);
5755

58-
var expectedDirectory = PathInternal.EnsureTrailingSeparator(Path.Combine(Directory.GetCurrentDirectory(), directory));
59-
Assert.Equal(Path.Combine(expectedDirectory, oldName), args.OldFullPath);
56+
Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), directory, oldName), args.OldFullPath);
6057
}
6158

6259
[Theory]
6360
[PlatformSpecific(TestPlatforms.AnyUnix)]
64-
[InlineData("", "", "")]
65-
[InlineData("", "foo.txt", "bar.txt")]
6661
[InlineData("bar", "foo.txt", "bar.txt")]
6762
[InlineData("bar/baz", "foo.txt", "bar.txt")]
6863
public static void RenamedEventArgs_ctor_OldFullPath_DirectoryIsRelativePath_Unix(string directory, string name, string oldName)
6964
{
7065
RenamedEventArgs args = new RenamedEventArgs(WatcherChangeTypes.All, directory, name, oldName);
7166

72-
var expectedDirectory = PathInternal.EnsureTrailingSeparator(Path.Combine(Directory.GetCurrentDirectory(), directory));
73-
Assert.Equal(Path.Combine(expectedDirectory, oldName), args.OldFullPath);
67+
Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), directory, oldName), args.OldFullPath);
7468
}
7569

7670
[Theory]
@@ -89,6 +83,7 @@ public static void RenamedEventArgs_ctor_When_EmptyOldFileName_Then_OldFullPathR
8983
[Fact]
9084
public static void RenamedEventArgs_ctor_Invalid()
9185
{
86+
Assert.Throws<ArgumentException>(() => new RenamedEventArgs((WatcherChangeTypes)0, "", "foo.txt", "bar.txt"));
9287
Assert.Throws<ArgumentNullException>(() => new RenamedEventArgs((WatcherChangeTypes)0, null, "foo.txt", "bar.txt"));
9388
}
9489
}

0 commit comments

Comments
 (0)