wendy

inotify based node watcher
git clone git://git.2f30.org/wendy.git
Log | Files | Refs | README | LICENSE

commit 143131288cbe6d8602ab925392a5b7537a026d85
parent 4ff6468aa26d8c9c7b85ca6cf6eac680e4d1ccc4
Author: Willy Goiffon <dev@z3bra.org>
Date:   Thu, 12 Mar 2020 19:30:52 +0100

Ignore hidden inodes by default

Diffstat:
Mwendy.c | 19+++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/wendy.c b/wendy.c @@ -38,14 +38,22 @@ char *evname[] = { }; int verbose = 0; +int aflag = 0, dflag = 0, rflag = 0; void usage(char *name) { - fprintf(stderr, "usage: %s [-vdr] [-m mask] [-w file] [command [args...]]\n", name); + fprintf(stderr, "usage: %s [-adrv] [-m mask] [-w file] [command [args...]]\n", name); exit(1); } +char * +basename(char *p) +{ + char *b = strrchr(p, '/'); + return *b ? b + 1 : p; +} + struct watcher * getwatcher(struct watchers *h, int wd) { @@ -119,7 +127,7 @@ wdpath(struct inotify_event *e, struct watcher *w) int main (int argc, char **argv) { - int fd, dflag = 0, rflag = 0; + int fd; uint8_t buf[EVSZ]; uint32_t mask = MASK; ssize_t len, off = 0; @@ -133,6 +141,9 @@ main (int argc, char **argv) perror("inotify_init"); ARGBEGIN { + case 'a': + aflag = 1; + break; case 'd': dflag = 1; break; @@ -173,6 +184,10 @@ main (int argc, char **argv) goto skip; } + /* skip hidden files when aflag is not set */ + if (!aflag && basename(wdpath(e, w))[0] == '.') + goto skip; + if (verbose && e->mask & IN_ALL_EVENTS) { printf("%s\t%s\n", evname[e->mask & IN_ALL_EVENTS], wdpath(e, w)); fflush(stdout);