Repository navigation
Description
Description
As per the documentation https://docs.microsoft.com/en-us/dotnet/api/system.io.filesystemeventargs.fullpath?view=net-6.0 the FullPath property should return a fully qualified path. However it appears the constructor for FileSystemEventArgs assumes the directory passed in is fully qualified: https://github.com/dotnet/runtime/blob/main/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemEventArgs.cs#L22
When used in conjunction with FileSystemWatcher it is possible for the path to be relative: https://github.com/dotnet/runtime/blob/main/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs#L260
Reproduction Steps
Repro code:
using System;
using System.IO;
namespace MyNamespace
{
class Program
{
static void Main()
{
using var watcher = new FileSystemWatcher(@"bar");
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed += OnChanged;
watcher.Filter = "*.txt";
watcher.IncludeSubdirectories = false;
watcher.EnableRaisingEvents = true;
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
private static void OnChanged(object sender, FileSystemEventArgs e)
{
if (e.ChangeType != WatcherChangeTypes.Changed)
{
return;
}
Console.WriteLine($"Changed: {e.FullPath}");
}
}
}
-
I created the following dir structure on my machine:
C:\foo\bar\footest.txt -
Set the working directory to be
C:\foo -
Run the program and then modify
footest.txtto trigger a changed event.
Expected behavior
Output should be:
Changed: C:\foo\bar\footest.txt
Actual behavior
Current output:
Changed: bar\footest.txt
Regression?
No response
Known Workarounds
Using Path.GetFullPath to fetch the fully qualified path
Console.WriteLine($"Changed: {Path.GetFullPath(e.FullPath)}");
Configuration
.Net 6.0
Windows 10 x64
After looking at the source I believe that this is not unique to Windows
Other information
No response
Activity
adamsitnik commentedon Dec 10, 2021
cc @jozkee
jozkee commentedon Dec 17, 2021
This would require a breaking change on
FileSystemEventArgs.FullPathwhich I'm inclined to accept given the name of the API.cc @ericstj @jeffhandley
slask commentedon Dec 18, 2021
Hi @jozkee. Can I take this issue?
jozkee commentedon Dec 18, 2021
@slask Yes, let me assign you. Thanks!
FullPath property now returns fully qualified path
OldFullPath returns fully qualified path
2 remaining items
Account for corner case when fullPath matches root
Handle relative paths from CWD in given drive
Clearly separated unix and windows test cases
Use EnsureTrailingSeparator instead of custom code
Keeping the old behavior with trailing separator
slask commentedon Jan 21, 2022
Linking docs issue dotnet/docs#27916
Used Path.Combien vs PathInternalEnsureSeparator
Added blank line for readability
62606 Return fully qualified path from FileSystemEventArgs (#63051)
jeffhandley commentedon May 5, 2022
After fixing #68566 with #68582, which was addressing a regression caused by #63051, which fixed this issue, I've reconsidered this original issue further. I think we should revert both #68582 and #63051 and return
FileSystemEventArgsandRenamedEventArgsback to their previous behavior and instead address this as a documentation issue.The regression that was reported involved using an empty directory name, and it was relying on
FullPathbeing relative to the process's directory. From that regression report, it's easy to imagine scenarios where the non-rooted path nature ofFullPathis utilized and perhaps even leveraged to combine that full path to a different root. I remember such code I wrote myself back in .NET Framework days that would be broken by this change.I'm going to submit a PR that reverts both #63051 and #68582, but leaves the additional tests in place, adapted to match the previous behavior.