Description
On Windows, when a directory watched by FileSystemWatcher is deleted, an error is raised that notifies the user of this. But on Linux, the user has no way of learning about it. From cursory reading of inotify docs, FileSystemWatcher could listen to the IN_DELETE_SELF event to make this work.
Reproduction Steps
Run the following code:
string dir = Path.Combine(Path.GetTempPath(), "fsw-demo");
if (Directory.Exists(dir)) Directory.Delete(dir, true);
Directory.CreateDirectory(dir);
using var watcher = new FileSystemWatcher(dir);
watcher.Created += (_, e) => Console.WriteLine($"Created: {e.Name}");
watcher.Deleted += (_, e) => Console.WriteLine($"Deleted: {e.Name}");
watcher.Error += (_, e) => Console.WriteLine($"Error: {e.GetException()}");
watcher.EnableRaisingEvents = true;
File.WriteAllText(Path.Combine(dir, "file.txt"), "text");
Directory.Delete(dir, true);
await Task.Delay(1000);
try { Directory.Delete(dir, true); } catch { }
Expected behavior
On Windows, it prints:
Created: file.txt
Error: System.ComponentModel.Win32Exception (5): Access is denied.
Actual behavior
On Linux (WSL), it prints instead:
Created: file.txt
Deleted: file.txt
Regression?
No.
Configuration
- .Net 11 Preview 2 on both OSes
- Ubuntu 22.04.1 LTS on WSL
Description
On Windows, when a directory watched by
FileSystemWatcheris deleted, an error is raised that notifies the user of this. But on Linux, the user has no way of learning about it. From cursory reading ofinotifydocs,FileSystemWatchercould listen to theIN_DELETE_SELFevent to make this work.Reproduction Steps
Run the following code:
Expected behavior
On Windows, it prints:
Actual behavior
On Linux (WSL), it prints instead:
Regression?
No.
Configuration