Bug 14663 - FileSystemWatcher does not perform as expected
Summary: FileSystemWatcher does not perform as expected
Status: CONFIRMED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 3.2.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-09-11 18:39 UTC by Bryan Moulton
Modified: 2014-12-09 01:20 UTC (History)
5 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
FSWatcher (23.39 KB, application/zip)
2013-09-11 18:39 UTC, Bryan Moulton
Details

Description Bryan Moulton 2013-09-11 18:39:56 UTC
Created attachment 4847 [details]
FSWatcher

From case #45521
Using the example provided, the FileSystemWatcher events aren't being handled properly. Only the Changed event is firing, and the ChangeType is always Changed.
Comment 1 Nikolay Ivanets 2013-09-12 06:29:23 UTC
Here is my initial request:

I use Mono on Mac OS X and it seems neither KeventWatcher nor DefaultWatcher implementation of IFileWatcher interface doesn't send Renamed event and thus it is impossible to catch this event when the user renames file or folder. I always get Deleted and Created events successively.
Comment 2 Aaron Bockover [MSFT] 2013-09-26 12:52:44 UTC
Use MonoMac.CoreServices.FSEvents for now. Here's a sample: https://github.com/xamarin/mac-samples/tree/master/FSEvents

Mono at some point in the future should probably use FSEvents internally for FileSystemWatcher, but it does not. The behavior you are looking for is however available in Xamarin.Mac.

Moving this to Mono itself since this is not a bug in Xamarin.Mac.
Comment 3 Nikolay Ivanets 2013-10-02 11:47:07 UTC
Yes, it is what I finally used.
Comment 4 Lorenzo Antonio Brito Morales 2014-05-08 03:43:32 UTC
Hi,  i would like to fix this. Is anyone
Comment 5 Lorenzo Antonio Brito Morales 2014-05-08 04:18:23 UTC
Sorry for my last comment, i would  like to fix, i have seen in code that all events are considerated. is this still a problem?
Comment 6 Nicolas Raoul 2014-12-09 01:20:25 UTC
Bug confirmed with Mono 3.10.0 on OS X 10.9.5.
I have created this watcher which inherits from FileSystemWatcher:

    Path = System.IO.Path.GetFullPath(folder);
    IncludeSubdirectories = true;
    Filter = "*";
    InternalBufferSize = 4 * 1024 * 16;
    NotifyFilter = NotifyFilters.Size |
               NotifyFilters.FileName | NotifyFilters.DirectoryName;
    Error += new ErrorEventHandler(OnError);
    Created += new FileSystemEventHandler(OnCreated);
    Deleted += new FileSystemEventHandler(OnDeleted);
    Changed += new FileSystemEventHandler(OnChanged);
    Renamed += new RenamedEventHandler(OnRenamed);

On both Windows and Mono/OS X, I tried renaming `file.txt` to `file2.txt` at the root of the watched folder.

==WINDOWS==
Works great: I receive one Renamed (name=file2.txt oldName=file.txt).

==MONO/OS X==
Unfortunately I receive 3 events:
1. Changed: file.txt
2. Created: file2.txt
3. Deleted: file.txt

Same result with Environment.SetEnvironmentVariable("MONO_MANAGED_WATCHER", "enabled");

This is problematic for my sync software: syncing deletion/creation to remote is inefficient and looses precious file metadata.

Note You need to log in before you can comment on or make changes to this bug.