summaryrefslogtreecommitdiff
path: root/fs/base.py
diff options
context:
space:
mode:
authorwillmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f>2010-12-20 19:10:18 +0000
committerwillmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f>2010-12-20 19:10:18 +0000
commit1ae3b0bbc0bc8336e96992e76baa746f66416ab2 (patch)
treebde72bb2a08a7b28aed760e913acadbf8fb6d3df /fs/base.py
parente0fd44efffba7b4011e7ee7ae8bd09a682fd24db (diff)
downloadpyfilesystem-1ae3b0bbc0bc8336e96992e76baa746f66416ab2.tar.gz
Added graceful handling of the directory structure changing during a 'walk'.
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@567 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/base.py')
-rw-r--r--fs/base.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/fs/base.py b/fs/base.py
index 9deac78..9ee2578 100644
--- a/fs/base.py
+++ b/fs/base.py
@@ -712,23 +712,31 @@ class FS(object):
while dirs:
current_path = dirs.pop()
paths = []
- for filename in listdir(current_path):
- path = pathjoin(current_path, filename)
- if self.isdir(path):
- if dir_wildcard(path):
- dirs.append(path)
- else:
- if wildcard(filename):
- paths.append(filename)
-
+ try:
+ for filename in listdir(current_path):
+ path = pathjoin(current_path, filename)
+ if self.isdir(path):
+ if dir_wildcard(path):
+ dirs.append(path)
+ else:
+ if wildcard(filename):
+ paths.append(filename)
+ except ResourceNotFoundError:
+ # Could happen if another thread / process deletes something whilst we are walking
+ pass
+
yield (current_path, paths)
elif search == "depth":
def recurse(recurse_path):
- for path in listdir(recurse_path, wildcard=dir_wildcard, full=True, dirs_only=True):
- for p in recurse(path):
- yield p
+ try:
+ for path in listdir(recurse_path, wildcard=dir_wildcard, full=True, dirs_only=True):
+ for p in recurse(path):
+ yield p
+ except ResourceNotFoundError:
+ # Could happen if another thread / process deletes something whilst we are walking
+ pass
yield (recurse_path, self.listdir(recurse_path, wildcard=wildcard, files_only=True))
for p in recurse(path):