Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add following symlink without infinite loop #83 #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions python2/pyinotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,8 +1924,8 @@ def add_watch(self, path, mask, proc_fun=None, rec=False,
@type proc_fun: function or ProcessEvent instance or instance of
one of its subclasses or callable object.
@param rec: Recursively add watches from path on all its
subdirectories, set to False by default (doesn't
follows symlinks in any case).
subdirectories, set to False by default (follows
symlinks).
@type rec: bool
@param auto_add: Automatically add watches on newly created
directories in watched parent |path| directory.
Expand Down Expand Up @@ -1956,17 +1956,19 @@ def add_watch(self, path, mask, proc_fun=None, rec=False,
if exclude_filter is None:
exclude_filter = self._exclude_filter

all_paths = set()
# normalize args as list elements
for npath in self.__format_param(path):
# unix pathname pattern expansion
for apath in self.__glob(npath, do_glob):
# recursively list subdirs according to rec param
for rpath in self.__walk_rec(apath, rec):
if not exclude_filter(rpath):
if not exclude_filter(rpath) and rpath not in all_path:
wd = ret_[rpath] = self.__add_watch(rpath, mask,
proc_fun,
auto_add,
exclude_filter)
all_paths.add(rpath)
if wd < 0:
err = ('add_watch: cannot watch %s WD=%d, %s' % \
(rpath, wd,
Expand Down Expand Up @@ -2132,7 +2134,7 @@ def get_path(self, wd):

def __walk_rec(self, top, rec):
"""
Yields each subdirectories of top, doesn't follow symlinks.
Yields each subdirectories of top, follows symlinks.
If rec is false, only yield top.

@param top: root directory.
Expand All @@ -2142,10 +2144,10 @@ def __walk_rec(self, top, rec):
@return: path of one subdirectory.
@rtype: string
"""
if not rec or os.path.islink(top) or not os.path.isdir(top):
if not rec or not os.path.isdir(top):
yield top
else:
for root, dirs, files in os.walk(top):
for root, dirs, files in os.walk(top, followlinks=True):
yield root

def rm_watch(self, wd, rec=False, quiet=True):
Expand Down
14 changes: 8 additions & 6 deletions python3/pyinotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -1901,8 +1901,8 @@ def add_watch(self, path, mask, proc_fun=None, rec=False,
@type proc_fun: function or ProcessEvent instance or instance of
one of its subclasses or callable object.
@param rec: Recursively add watches from path on all its
subdirectories, set to False by default (doesn't
follows symlinks in any case).
subdirectories, set to False by default (follows
symlinks).
@type rec: bool
@param auto_add: Automatically add watches on newly created
directories in watched parent |path| directory.
Expand Down Expand Up @@ -1932,6 +1932,7 @@ def add_watch(self, path, mask, proc_fun=None, rec=False,
if exclude_filter is None:
exclude_filter = self._exclude_filter

all_paths = set()
# normalize args as list elements
for npath in self.__format_param(path):
# Require that path be a unicode string
Expand All @@ -1943,11 +1944,12 @@ def add_watch(self, path, mask, proc_fun=None, rec=False,
for apath in self.__glob(npath, do_glob):
# recursively list subdirs according to rec param
for rpath in self.__walk_rec(apath, rec):
if not exclude_filter(rpath):
if not exclude_filter(rpath) and rpath not in all_path:
wd = ret_[rpath] = self.__add_watch(rpath, mask,
proc_fun,
auto_add,
exclude_filter)
all_paths.add(rpath)
if wd < 0:
err = ('add_watch: cannot watch %s WD=%d, %s' % \
(rpath, wd,
Expand Down Expand Up @@ -2113,7 +2115,7 @@ def get_path(self, wd):

def __walk_rec(self, top, rec):
"""
Yields each subdirectories of top, doesn't follow symlinks.
Yields each subdirectories of top, follows symlinks.
If rec is false, only yield top.

@param top: root directory.
Expand All @@ -2123,10 +2125,10 @@ def __walk_rec(self, top, rec):
@return: path of one subdirectory.
@rtype: string
"""
if not rec or os.path.islink(top) or not os.path.isdir(top):
if not rec or not os.path.isdir(top):
yield top
else:
for root, dirs, files in os.walk(top):
for root, dirs, files in os.walk(top, followlinks=True):
yield root

def rm_watch(self, wd, rec=False, quiet=True):
Expand Down