Skip to content

Commit a60abe4

Browse files
authored
Merge pull request #92 from Facepunch/fix/sub-watcher-case-sensitive
Fix SubFileSystem watcher (sometimes) silently discarding events
2 parents a4b9faf + a68e9e9 commit a60abe4

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/Zio.Tests/FileSystems/TestSubFileSystem.cs

+37
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,43 @@ public void TestWatcher()
7474
Assert.True(gotChange);
7575
}
7676

77+
[SkippableTheory]
78+
[InlineData("/test", "/test", "/foo.txt")]
79+
[InlineData("/test", "/test", "/~foo.txt")]
80+
[InlineData("/test", "/TEST", "/foo.txt")]
81+
[InlineData("/test", "/TEST", "/~foo.txt")]
82+
[InlineData("/verylongname", "/VERYLONGNAME", "/foo.txt")]
83+
[InlineData("/verylongname", "/VERYLONGNAME", "/~foo.txt")]
84+
public void TestWatcherCaseSensitive(string physicalDir, string subDir, string filePath)
85+
{
86+
Skip.IfNot(IsWindows, "This test involves case insensitivity on Windows");
87+
88+
var physicalFs = GetCommonPhysicalFileSystem();
89+
physicalFs.CreateDirectory(physicalDir);
90+
91+
Assert.True(physicalFs.DirectoryExists(physicalDir));
92+
Assert.True(physicalFs.DirectoryExists(subDir));
93+
94+
var subFs = new SubFileSystem(physicalFs, subDir);
95+
var watcher = subFs.Watch("/");
96+
var waitHandle = new ManualResetEvent(false);
97+
98+
watcher.Created += (sender, args) =>
99+
{
100+
if (args.FullPath == filePath)
101+
{
102+
waitHandle.Set();
103+
}
104+
};
105+
106+
watcher.IncludeSubdirectories = true;
107+
watcher.EnableRaisingEvents = true;
108+
109+
physicalFs.WriteAllText($"{physicalDir}{filePath}", "test");
110+
111+
Assert.True(waitHandle.WaitOne(100));
112+
}
113+
77114
[SkippableFact]
78115
public void TestDirectorySymlink()
79116
{

src/Zio/FileSystems/PhysicalFileSystem.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ protected override UPath ConvertPathFromInternalImpl(string innerPath)
977977
if (innerPath.StartsWith(@"\\", StringComparison.Ordinal) || innerPath.StartsWith(@"\?", StringComparison.Ordinal))
978978
throw new NotSupportedException($"Path starting with `\\\\` or `\\?` are not supported -> `{innerPath}` ");
979979

980-
var absolutePath = Path.GetFullPath(innerPath);
980+
var absolutePath = Path.IsPathRooted(innerPath) ? innerPath : Path.GetFullPath(innerPath);
981981
var driveIndex = absolutePath.IndexOf(":\\", StringComparison.Ordinal);
982982
if (driveIndex != 1)
983983
throw new ArgumentException($"Expecting a drive for the path `{absolutePath}`");

0 commit comments

Comments
 (0)