Skip to content

Commit

Permalink
Merge pull request gorakhargosh#281 from theospears/do-not-crash-on-d…
Browse files Browse the repository at this point in the history
…ir-deletion

Avoid race condition crash on directory deletion
  • Loading branch information
tamland committed Oct 25, 2014
2 parents 168fb38 + ae398b3 commit 99f0909
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/watchdog/utils/dirsnapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"""

import errno
import os
from stat import S_ISDIR
from watchdog.utils import platform
Expand Down Expand Up @@ -208,7 +209,16 @@ def __init__(self, path, recursive=True,
self._inode_to_path[(st.st_ino, st.st_dev)] = path

def walk(root):
paths = [os.path.join(root, name) for name in listdir(root)]
try:
paths = [os.path.join(root, name) for name in listdir(root)]
except OSError as e:
# Directory may have been deleted between finding it in the directory
# list of its parent and trying to delete its contents. If this
# happens we treat it as empty.
if e.errno == errno.ENOENT:
return
else:
raise
entries = []
for p in paths:
try:
Expand Down

0 comments on commit 99f0909

Please sign in to comment.