if hasattr(self._notifier, 'set_pending_delay'):
self._notifier.set_pending_delay(pending_delay)
+ # IN_EXCL_UNLINK suppresses events for files that have been unlinked from the watched directory.
+ # The constant is missing from Twisted (see <https://twistedmatrix.com/trac/ticket/7789>) so we
+ # define it here.
+ inotify_IN_EXCL_UNLINK = 0x04000000
+
# We don't watch for IN_CREATE, because that would cause us to read and upload a
# possibly-incomplete file before the application has closed it. There should always
# be an IN_CLOSE_WRITE after an IN_CREATE (I think).
+ #
+ # IN_ONLY_DIR causes an error if the target path does not reference a directory.
# TODO: what about IN_MOVE_SELF or IN_UNMOUNT?
- self.mask = inotify.IN_CLOSE_WRITE | inotify.IN_MOVED_TO | inotify.IN_ONLYDIR
+ self.mask = inotify.IN_CLOSE_WRITE | inotify.IN_MOVED_TO | inotify_IN_EXCL_UNLINK | inotify.IN_ONLYDIR
self._notifier.watch(self._local_path, mask=self.mask, callbacks=[self._notify],
recursive=True)