Open denilsonsa opened 8 years ago
Seeing the same issue. Possible fix?
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.
This issue also breaks fswatch -1 -m inotify_monitor
behaviour
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$//
'
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.
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.
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 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 thanks. Did you use any other tool instead?
@ahmgithubahm For my purpose, lsyncd was a nice alternative. Took me some time to properly write a configuration file, but it worked fine.
You had one job fswatch... uninstalled, I'll use inotifywait.
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.
How to reproduce:
fswatch .
in one terminal (or `fswatch -m inotify_monitor).ls the_directory_where_you_are
orcat some_file_inside_the_directory
Results (output of
-x
option):Expected results: Only modified files/directories should be changed. Reading a directory or a file should not have any impact.