From 092311811893602d69302b3b74b5b2b3d8efc7a4 Mon Sep 17 00:00:00 2001 From: Sly_tom_cat Date: Tue, 18 Oct 2016 16:27:42 +0300 Subject: [PATCH 1/2] Fix for issue #133 --- python3/pyinotify.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python3/pyinotify.py b/python3/pyinotify.py index bc24313..91535e1 100755 --- a/python3/pyinotify.py +++ b/python3/pyinotify.py @@ -2121,6 +2121,7 @@ def rm_watch(self, wd, rec=False, quiet=True): lwd = self.__get_sub_rec(lwd) ret_ = {} # return {wd: bool, ...} + to_del = [] for awd in lwd: # remove watch wd_ = self._inotify_wrapper.inotify_rm_watch(self._fd, awd) @@ -2135,8 +2136,10 @@ def rm_watch(self, wd, rec=False, quiet=True): # Remove watch from our dictionary if awd in self._wmd: - del self._wmd[awd] + to_del.append(awd) ret_[awd] = True + for awd in to_del: + del self._wmd[awd] log.debug('Watch WD=%d (%s) removed', awd, self.get_path(awd)) return ret_ From 39d2b0eb7812e93a282a7aeb20fd2bd94260d61e Mon Sep 17 00:00:00 2001 From: Sly_tom_cat Date: Tue, 18 Oct 2016 16:46:11 +0300 Subject: [PATCH 2/2] Fix for issue #133 v.2 --- python2/pyinotify.py | 3 ++- python3/pyinotify.py | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/python2/pyinotify.py b/python2/pyinotify.py index d2f0816..fa9d9b0 100755 --- a/python2/pyinotify.py +++ b/python2/pyinotify.py @@ -1979,7 +1979,8 @@ def __get_sub_rec(self, lpath): root = os.path.normpath(root) # recursion lend = len(root) - for iwd in self._wmd.items(): + wmd = self._wmd.copy().items() + for iwd in wmd: cur = iwd[1].path pref = os.path.commonprefix([root, cur]) if root == os.sep or (len(pref) == lend and \ diff --git a/python3/pyinotify.py b/python3/pyinotify.py index 91535e1..cc3aa6e 100755 --- a/python3/pyinotify.py +++ b/python3/pyinotify.py @@ -1958,7 +1958,8 @@ def __get_sub_rec(self, lpath): root = os.path.normpath(root) # recursion lend = len(root) - for iwd in self._wmd.items(): + wmd = self._wmd.copy().items() + for iwd in wmd: cur = iwd[1].path pref = os.path.commonprefix([root, cur]) if root == os.sep or (len(pref) == lend and \ @@ -2121,7 +2122,6 @@ def rm_watch(self, wd, rec=False, quiet=True): lwd = self.__get_sub_rec(lwd) ret_ = {} # return {wd: bool, ...} - to_del = [] for awd in lwd: # remove watch wd_ = self._inotify_wrapper.inotify_rm_watch(self._fd, awd) @@ -2136,10 +2136,8 @@ def rm_watch(self, wd, rec=False, quiet=True): # Remove watch from our dictionary if awd in self._wmd: - to_del.append(awd) + del self._wmd[awd] ret_[awd] = True - for awd in to_del: - del self._wmd[awd] log.debug('Watch WD=%d (%s) removed', awd, self.get_path(awd)) return ret_