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

How to notify for write operations only? (using -m inotify_monitor on linux) #322

Open pmorch opened 1 month ago

pmorch commented 1 month ago

I was expecting only to see notifications for "write" operations that modify the file system. Is that a valid assumption?

I get 6 notifications from /bin/ls emptyDir. Am I misunderstanding something fundamental here?

Details

Terminal one:

$ mkdir emptyDir

# This uses -m inotify_monitor
$ fswatch -xr emptyDir
/home/pmorch/emptyDir IsDir
/home/pmorch/emptyDir PlatformSpecific
/home/pmorch/emptyDir IsDir
/home/pmorch/emptyDir PlatformSpecific
/home/pmorch/emptyDir IsDir
/home/pmorch/emptyDir PlatformSpecific

Why am I notified when starting up fswatch? Clearly nobody is writing to emptyDir yet.

Terminal two:

$ /bin/ls emptyDir
(no output from empty emptyDir)

But then in terminal one I see:

/home/pmorch/emptyDir IsDir
/home/pmorch/emptyDir PlatformSpecific
/home/pmorch/emptyDir IsDir
/home/pmorch/emptyDir PlatformSpecific
/home/pmorch/emptyDir IsDir
/home/pmorch/emptyDir PlatformSpecific

Why does /bin/ls emptyDir create 6 events?

If I use the non-standard -m poll_monitor I get events only for modifications.

How do I use the default inotify_monitor and only get notified for modifications? And if that is possible, why isn't it the default like it apparently is for -m poll_monitor?

Versions and environment

I've tried on machine1:

on machine2: