Skip to content

Commit

Permalink
Merge pull request #92 from Facepunch/fix/sub-watcher-case-sensitive
Browse files Browse the repository at this point in the history
Fix SubFileSystem watcher (sometimes) silently discarding events
  • Loading branch information
xoofx authored Jun 21, 2024
2 parents a4b9faf + a68e9e9 commit a60abe4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/Zio.Tests/FileSystems/TestSubFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,43 @@ public void TestWatcher()
Assert.True(gotChange);
}

[SkippableTheory]
[InlineData("/test", "/test", "/foo.txt")]
[InlineData("/test", "/test", "/~foo.txt")]
[InlineData("/test", "/TEST", "/foo.txt")]
[InlineData("/test", "/TEST", "/~foo.txt")]
[InlineData("/verylongname", "/VERYLONGNAME", "/foo.txt")]
[InlineData("/verylongname", "/VERYLONGNAME", "/~foo.txt")]
public void TestWatcherCaseSensitive(string physicalDir, string subDir, string filePath)
{
Skip.IfNot(IsWindows, "This test involves case insensitivity on Windows");

var physicalFs = GetCommonPhysicalFileSystem();
physicalFs.CreateDirectory(physicalDir);

Assert.True(physicalFs.DirectoryExists(physicalDir));
Assert.True(physicalFs.DirectoryExists(subDir));

var subFs = new SubFileSystem(physicalFs, subDir);
var watcher = subFs.Watch("/");
var waitHandle = new ManualResetEvent(false);

watcher.Created += (sender, args) =>
{
if (args.FullPath == filePath)
{
waitHandle.Set();
}
};

watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;

physicalFs.WriteAllText($"{physicalDir}{filePath}", "test");

Assert.True(waitHandle.WaitOne(100));
}

[SkippableFact]
public void TestDirectorySymlink()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Zio/FileSystems/PhysicalFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ protected override UPath ConvertPathFromInternalImpl(string innerPath)
if (innerPath.StartsWith(@"\\", StringComparison.Ordinal) || innerPath.StartsWith(@"\?", StringComparison.Ordinal))
throw new NotSupportedException($"Path starting with `\\\\` or `\\?` are not supported -> `{innerPath}` ");

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

0 comments on commit a60abe4

Please sign in to comment.