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

Incorrect Filename and FullPath from FileSystemWatcher under Win32 #21677

Open
klightspeed opened this issue Jul 16, 2023 · 0 comments · May be fixed by #21680
Open

Incorrect Filename and FullPath from FileSystemWatcher under Win32 #21677

klightspeed opened this issue Jul 16, 2023 · 0 comments · May be fixed by #21680

Comments

@klightspeed
Copy link

klightspeed commented Jul 16, 2023

When running under Windows or Wine (and likely other systems where mono does not have native file change notifications), FileSystemWatcher is returning the full path and not the relative path in the FileSystemEventArgs.Filename property, and that is being concatenated with the FileSystemWatcher's path

Steps to Reproduce

  1. Create a FileSystemWatcher watching for changes in a directory
  2. Add or modify a file in that directory
using System;
using System.Threading;

namespace TestFileSystemWatcher
{
    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine($"Watching {args[0]} with filter {args[1]}");
            var watcher = new System.IO.FileSystemWatcher();
            watcher.Path = args[0];
            watcher.Filter = args[1];
            watcher.IncludeSubdirectories = false;
            watcher.NotifyFilter = System.IO.NotifyFilters.FileName;
            watcher.Changed += Watcher_Event;
            watcher.Created += Watcher_Event;
            watcher.Renamed += Watcher_Event;
            watcher.Deleted += Watcher_Event;
            watcher.EnableRaisingEvents = true;

            Thread.Sleep(Timeout.Infinite);
        }

        private static void Watcher_Event(object sender, System.IO.FileSystemEventArgs e)
        {
            Console.WriteLine($"Change: Filename={e.Name}; FullPath={e.FullPath}; ChangeType={e.ChangeType}");
        }
    }
}

Current Behavior

>"C:\Program Files\Mono\bin\mono.exe" TestFileSystemWatcher.exe "F:\Data\TestWatcher" "*.txt"
Watching F:\Data\TestWatcher with filter *.txt
Change: Filename=F:\Data\TestWatcher\test.txt; FullPath=F:\Data\TestWatcher\F:\Data\TestWatcher\test.txt; ChangeType=Changed

Expected Behavior

>TestFileSystemWatcher.exe "F:\Data\TestWatcher" "*.txt"
Watching F:\Data\TestWatcher with filter *.txt
Change: Filename=test.txt; FullPath=F:\Data\TestWatcher\test.txt; ChangeType=Changed

On which platforms did you notice this

[ ] macOS
[ ] Linux
[x] Windows
[x] Wine

Version Used:

6.12.0.199

edit: 5.20.1.34 was the last version to correctly combine the watcher path with the filename into the FullPath; 6.0 onwards concatenates the watcher path with the filename into the FullPath.

klightspeed added a commit to EDDiscovery/EliteDangerousCore that referenced this issue Jul 16, 2023
Mono running under Windows or Wine sets the `Name` in the `FileSystemEventArgs` to the absolute path of the file rather than the relative path, resulting in `FullPath` being an invalid path.  Work around this by using `Name` if it's an absolute path.

This has been reported as mono/mono#21677
robbyxp1 pushed a commit to EDDiscovery/EliteDangerousCore that referenced this issue Aug 7, 2023
Mono running under Windows or Wine sets the `Name` in the `FileSystemEventArgs` to the absolute path of the file rather than the relative path, resulting in `FullPath` being an invalid path.  Work around this by using `Name` if it's an absolute path.

This has been reported as mono/mono#21677
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant