emcrisostomo / fswatch

A cross-platform file change monitor with multiple backends: Apple OS X File System Events, *BSD kqueue, Solaris/Illumos File Events Notification, Linux inotify, Microsoft Windows and a stat()-based backend.
https://emcrisostomo.github.io/fswatch/
GNU General Public License v3.0
4.96k stars 327 forks source link

macOS and linux: no way to correlate rename events #278

Closed christian-schulze closed 1 year ago

christian-schulze commented 3 years ago

File move operations on MacOS are reported by fswatch as pairs of Renamed events. The first event being the source and the second event being the destination.

Given the following scenario, the events are not reported in the correct order:

touch a 1; mv a b; mv 1 2; mv b c; mv 2 3

Actual output:

1) a -> CREATED RENAMED IS_FILE 2) 1 -> CREATED RENAMED IS_FILE 3) b -> RENAMED IS_FILE 4) c -> RENAMED IS_FILE 5) 2 -> RENAMED IS_FILE 6) 3 -> RENAMED IS_FILE

Given these results, there is no way to correlate event 3 with 1, and event 5 with 2.

If the Created and Renamed events were not merged into one event, then this might behave as expected. Is this something that fswatch is doing explicitly? Or is this what the MacOS API is reporting?

emcrisostomo commented 2 years ago

This is exactly what the macOS API is reporting, I'm afraid. There should be a way to correlate multiple rename events using inode identifiers (available since macOS 10.13 High Sierra IIRC), but I haven't looked into it yet.

christian-schulze commented 2 years ago

@emcrisostomo yes agreed, I've actually patched the fsevents node module to support this: https://github.com/fsevents/fsevents/pull/360

emcrisostomo commented 2 years ago

Thanks for the feedback @christian-schulze

emcrisostomo commented 1 year ago

I've update the issue since I've fixed this in the feature branch for both the fsevents_monitor and the inotify_monitor.

emcrisostomo commented 1 year ago

Merged into master.