Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SubFileSystem watcher (sometimes) silently discards events #91

Closed
Metapyziks opened this issue Jun 21, 2024 · 0 comments · Fixed by #92
Closed

SubFileSystem watcher (sometimes) silently discards events #91

Metapyziks opened this issue Jun 21, 2024 · 0 comments · Fixed by #92
Labels

Comments

@Metapyziks
Copy link
Contributor

Metapyziks commented Jun 21, 2024

Summary

This is a Windows-specific bug caused by System.IO.Path.GetFullPath calling System.IO.PathHelper.TryExpandShortFileName for paths containing a ~.

Symptoms

IFileSystemWatcher events created from a SubFileSystem will be silently discarded if all these conditions are met:

  • We're on Windows
  • The path given when creating the SubFileSystem has incorrect case
  • The path segments with incorrect case are short enough to be a SFN
  • The changed file name includes a ~ anywhere

We noticed this when watching for .cs file changes while editing using Visual Studio. VS won't directly write to files when saving, instead creating a temporary file named something like Example~xxxx.tmp, which is then renamed to replace the actual target file.

Cause

GetFullPath gets called by all the PhysicalFileSystem.Watcher.Remap methods via ConvertPathFromInternalImpl:

var absolutePath = Path.GetFullPath(innerPath);

This can change the case of the path - even if it was already rooted - if it contains a ~.

Then, SubFileSystem.Watcher.TryConvertPath checks if paths are contained in its SubPath by calling UPath.IsInDirectory, which is case-sensitive:

if (target.Length < dir.Length || !target.StartsWith(dir, StringComparison.Ordinal))

When this fails, the event gets silently discarded.

Reproduction

Here's a test demonstrating this:

https://github.com/Facepunch/zio/blob/073a0201895ab9af996c1b30790fbe3c2ccaa5d0/src/Zio.Tests/FileSystems/TestSubFileSystem.cs#L77-L112

Only one case fails: the one where all the conditions above are met.

image

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants