diff options
author | Sebastien Martini <seb@dbzteam.org> | 2009-10-29 19:56:05 +0100 |
---|---|---|
committer | Sebastien Martini <seb@dbzteam.org> | 2009-10-29 19:56:05 +0100 |
commit | eba40b6fde274ee44ad98ad0c5b438def813181a (patch) | |
tree | 5d410bafaaae63c830624f8041862e60c48bb5b9 | |
parent | 86e0ee2cb584e232fbff3c6473caca7f46573d65 (diff) | |
download | pyinotify-eba40b6fde274ee44ad98ad0c5b438def813181a.tar.gz |
Rename all watched sub directories paths of a given parent
directory when this parent directory is moved and is assigned a
new pathname (contributed by john@feurix.com).
-rwxr-xr-x | pyinotify.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/pyinotify.py b/pyinotify.py index e9ae755..3a662e7 100755 --- a/pyinotify.py +++ b/pyinotify.py @@ -729,7 +729,15 @@ class _SysProcessEvent(_ProcessEvent): src_path = watch_.path mv_ = self._mv.get(src_path) if mv_: - watch_.path = mv_[0] + dest_path = mv_[0] + watch_.path = dest_path + # The next loop renames all watches. + # It seems that IN_MOVE_SELF does not provide IN_ISDIR information + # therefore the next loop is iterated even if raw_event is a file. + for w in self._watch_manager.watches.itervalues(): + if w.path.startswith(src_path): + # Note that dest_path is a normalized path. + w.path = os.path.join(dest_path, w.path[len(dest_path):]) else: log.error("The pathname '%s' of this watch %s has probably changed " "and couldn't be updated, so it cannot be trusted " @@ -741,7 +749,6 @@ class _SysProcessEvent(_ProcessEvent): os.path.pardir))) if not watch_.path.endswith('-unknown-path'): watch_.path += '-unknown-path' - # FIXME: should we pass the cookie even if this is not standard? return self.process_default(raw_event) def process_IN_Q_OVERFLOW(self, raw_event): @@ -1570,6 +1577,16 @@ class WatchManager: except KeyError, err: log.error(str(err)) + @property + def watches(self): + """ + Get a reference on the internal watch manager dictionary. + + @return: Internal watch manager dictionary. + @rtype: dict + """ + return self._wmd + def __add_watch(self, path, mask, proc_fun, auto_add): """ Add a watch on path, build a Watch object and insert it in the |