From 279fb959790fb8e5bfc20e3ea7b797bcaddce56f Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Thu, 11 Jun 2009 13:45:02 +0200 Subject: [PATCH] Watch for IN_CLOSE_WRITE in addition to IN_MODIFY and IN_CREATE When receiving IN_CREATE or IN_MODIFY, there's no guarantee the file is in its final state. Similarly, IN_MOVED_TO doesn't guarantee the file is available when we receive it. And it actually isn't. Watching for IN_CLOSE_WRITE fixes all that. --- src/filescanner.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/filescanner.c b/src/filescanner.c index 3119a1a8..b61ca3c1 100644 --- a/src/filescanner.c +++ b/src/filescanner.c @@ -529,7 +529,7 @@ process_directory(int libidx, char *path, int flags) memset(&wi, 0, sizeof(struct watch_info)); /* Add inotify watch */ - wi.wd = inotify_add_watch(inofd, path, IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVE | IN_DELETE | IN_DELETE_SELF | IN_MOVE_SELF); + wi.wd = inotify_add_watch(inofd, path, IN_CREATE | IN_DELETE | IN_MODIFY | IN_CLOSE_WRITE | IN_MOVE | IN_DELETE | IN_DELETE_SELF | IN_MOVE_SELF); if (wi.wd < 0) { DPRINTF(E_WARN, L_SCAN, "Could not create inotify watch for %s: %s\n", path, strerror(errno)); @@ -717,7 +717,7 @@ process_inotify_file(struct watch_info *wi, char *path, struct inotify_event *ie ie->mask |= IN_CREATE; } - if (ie->mask & (IN_MODIFY | IN_CREATE)) + if (ie->mask & (IN_MODIFY | IN_CREATE | IN_CLOSE_WRITE)) { ret = lstat(path, &sb); if (ret < 0)