diff options
author | Sebastien Martini <seb@dbzteam.org> | 2011-04-05 14:30:16 +0200 |
---|---|---|
committer | Sebastien Martini <seb@dbzteam.org> | 2011-04-05 14:30:16 +0200 |
commit | f4ce646a42b040eb08b0b87dacd594c0ba0df4f9 (patch) | |
tree | 18a6e2198365c21694817486a1aec014b690e31d /python2 | |
parent | fc47e5b47355e2dd1859d05c1f4a6b67976682b8 (diff) | |
download | pyinotify-f4ce646a42b040eb08b0b87dacd594c0ba0df4f9.tar.gz |
Emit artificial IN_CREATE events on recursive files creations.
This commit should help mitigating long standing issue "Missing
IN_CREATE events" https://github.com/seb-m/pyinotify/issues#issue/2
Note that symlinks are handled as files and that no similar
treatment is applied to IN_MOVE_TO events, because even if moved
files are new watched items, there aren't newly created per se by
the filesystem.
Diffstat (limited to 'python2')
-rwxr-xr-x | python2/pyinotify.py | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/python2/pyinotify.py b/python2/pyinotify.py index 1372951..739f1e9 100755 --- a/python2/pyinotify.py +++ b/python2/pyinotify.py @@ -762,22 +762,28 @@ class _SysProcessEvent(_ProcessEvent): rec=False, auto_add=watch_.auto_add, exclude_filter=watch_.exclude_filter) - # Trick to handle mkdir -p /t1/t2/t3 where t1 is watched and - # t2 and t3 are created. - # Since the directory is new, then everything inside it - # must also be new. + # Trick to handle mkdir -p /d1/d2/t3 where d1 is watched and + # d2 and t3 (directory or file) are created. + # Since the directory d2 is new, then everything inside it must + # also be new. created_dir_wd = addw_ret.get(created_dir) - if (created_dir_wd is not None) and created_dir_wd > 0: + if (created_dir_wd is not None) and (created_dir_wd > 0): for name in os.listdir(created_dir): inner = os.path.join(created_dir, name) - if (os.path.isdir(inner) and - self._watch_manager.get_wd(inner) is None): - # Generate (simulate) creation event for sub - # directories. - rawevent = _RawEvent(created_dir_wd, - IN_CREATE | IN_ISDIR, - 0, name) - self._notifier.append_event(rawevent) + if self._watch_manager.get_wd(inner) is not None: + continue + # Generate (simulate) creation events for sub- + # directories and files. + if os.path.isfile(inner): + # symlinks are handled as files. + flags = IN_CREATE + elif os.path.isdir(inner): + flags = IN_CREATE | IN_ISDIR + else: + # This path should not be taken. + continue + rawevent = _RawEvent(created_dir_wd, flags, 0, name) + self._notifier.append_event(rawevent) return self.process_default(raw_event) def process_IN_MOVED_FROM(self, raw_event): @@ -1575,7 +1581,7 @@ class Watch: Represent a watch, i.e. a file or directory being watched. """ - __slots__ = ('wd', 'path', 'mask', 'proc_fun', 'auto_add', + __slots__ = ('wd', 'path', 'mask', 'proc_fun', 'auto_add', 'exclude_filter', 'dir') def __init__(self, wd, path, mask, proc_fun, auto_add, exclude_filter): |