fswatch icon indicating copy to clipboard operation
fswatch copied to clipboard

fswatch reports files/directories that are being read (Linux/Ubuntu/inotify_monitor)

Open denilsonsa opened this issue 8 years ago • 12 comments

How to reproduce:

  1. Run fswatch . in one terminal (or `fswatch -m inotify_monitor).
  2. Open another terminal.
  3. Execute one of: ls the_directory_where_you_are or cat some_file_inside_the_directory

Results (output of -x option):

/home/foo/bar IsDir
/home/foo/bar PlatformSpecific

Expected results: Only modified files/directories should be changed. Reading a directory or a file should not have any impact.

denilsonsa avatar Sep 15 '16 14:09 denilsonsa

Seeing the same issue. Possible fix?

mfornasa avatar Sep 30 '16 16:09 mfornasa

Quick and dirty workaround: use the following shell script wrapper.

#!/bin/sh
/full/path/to/fswatch -x "$@" | sed '
    s/ IsDir//
    s/ PlatformSpecific//
    /^[^ ]*$/d
    s/ [a-zA-Z]\+$//
'

This wrapper will not work if your files contain space characters.

denilsonsa avatar Oct 04 '16 14:10 denilsonsa

This issue also breaks fswatch -1 -m inotify_monitor behaviour

bombazook avatar Sep 27 '17 16:09 bombazook

Slightly better wrapper script:

#!/bin/sh
/full/path/to/fswatch -x "$@" | sed '
    s/ IsDir//
    s/ PlatformSpecific//
    s/\( [A-Z][a-zA-Z]\+\)\+$/ XXX_KEEP_THIS_LINE_XXX/
    / XXX_KEEP_THIS_LINE_XXX$/!d
    s/ XXX_KEEP_THIS_LINE_XXX$//
'

denilsonsa avatar Jul 18 '18 12:07 denilsonsa

I highly recommend to use fswatch with 'poll monitor' on LINUX systems fswatch -r -m poll_monitor /your/path => fast and reliable recursive scanning, takes not a lot of CPU (~5% , 4 cores, i5-2450M), but less than 10MB ram. I am scanning ~32.000 files in ~2800 sub-directories. It reacts on changes/updates in 0.1second.

Hope, it helps someone.

ghost avatar Aug 22 '18 10:08 ghost

FS watch is a general file system watcher. Given the nature of the events that the underlying system call does, reading a directory is an event.. fswatch has some capability for event filtering. Using it with -n (numeric flags) allows you to bitwise OR it to the flags of interest.

sgbotsford avatar Sep 07 '18 14:09 sgbotsford

Slightly better wrapper script:

#!/bin/sh
/full/path/to/fswatch -x "$@" | sed '
    s/ IsDir//
    s/ PlatformSpecific//
    s/\( [A-Z][a-zA-Z]\+\)\+$/ XXX_KEEP_THIS_LINE_XXX/
    / XXX_KEEP_THIS_LINE_XXX$/!d
    s/ XXX_KEEP_THIS_LINE_XXX$//
'

Would love a little explanation of what the last three lines are there to achieve ?

ahmgithubahm avatar May 10 '20 14:05 ahmgithubahm

@ahmgithubahm It's been a couple of years, but I think I still remember why. The output could be something like this:

path/foo/bar IsDir
path/foo/bac PlatformSpecific
path/foo/baz PlatformSpecific SomeOtherReason
path/foo/bay SomeOtherReason

For each path, there could be multiple reasons why it was listed. (I don't remember if this was the case; I assume so, otherwise why would I write those extra lines? Please correct me if I'm wrong!)

The naive script would filter the third line, but the improved version would keep it.

I stopped using fswatch (and the wrapper script) shortly after writing that workaround, so I can't provide any further help.

denilsonsa avatar May 11 '20 07:05 denilsonsa

@denilsonsa thanks. Did you use any other tool instead?

ahmgithubahm avatar May 11 '20 10:05 ahmgithubahm

@ahmgithubahm For my purpose, lsyncd was a nice alternative. Took me some time to properly write a configuration file, but it worked fine.

denilsonsa avatar May 11 '20 13:05 denilsonsa

You had one job fswatch... uninstalled, I'll use inotifywait.

sswam avatar Mar 18 '21 07:03 sswam

This is by design: fswatch dumps whatever events its backend raises. Perhaps filtering could be improved, but what's described in this issue is expected behaviour. Actually, @sgbotsford has described how I'm using it when I need to filter events.

Furthermore, I'm adding a feature to 'bubble' events received in the same batch, and this will alleviate cases in which some backends generate multiple events for the same path with different flags.

emcrisostomo avatar Jun 17 '21 09:06 emcrisostomo