From eba40b6fde274ee44ad98ad0c5b438def813181a Mon Sep 17 00:00:00 2001 From: Sebastien Martini Date: Thu, 29 Oct 2009 19:56:05 +0100 Subject: 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). --- pyinotify.py | 21 +++++++++++++++++++-- 1 file 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 -- cgit v1.2.1