Skip to content

Commit

Permalink
Snapshot: don't walk directories without read permissions
Browse files Browse the repository at this point in the history
Original patch by Joshua Skelton (@joshuaskelly) on issue gorakhargosh#408.
  • Loading branch information
BoboTiG committed Jun 11, 2019
1 parent 8b94506 commit e9c84d5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/watchdog/utils/dirsnapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def walk(root):
# list of its parent and trying to delete its contents. If this
# happens we treat it as empty. Likewise if the directory was replaced
# with a file of the same name (less likely, but possible).
if e.errno == errno.ENOENT or e.errno == errno.ENOTDIR:
if e.errno in (errno.ENOENT, errno.ENOTDIR):
return
else:
raise
Expand All @@ -234,9 +234,16 @@ def walk(root):
yield _
if recursive:
for path, st in entries:
if S_ISDIR(st.st_mode):
for _ in walk(path):
yield _
try:
if S_ISDIR(st.st_mode):
for _ in walk(path):
yield _
except (IOError, OSError) as e:
# IOError for Python 2
# OSError for Python 3
# (should be only PermissionError when dropping Python 2 support)
if e.errno != errno.EACCES:
raise

for p, st in walk(path):
i = (st.st_ino, st.st_dev)
Expand Down

0 comments on commit e9c84d5

Please sign in to comment.