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.
This commit is contained in:
Julien BLACHE 2009-06-11 13:45:02 +02:00
parent 467b177c17
commit 279fb95979

View File

@ -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)