Commit 64e80d49 by willmcgugan

Added graceful handling of the directory structure changing during a 'walk'.

parent 0bd14855
...@@ -712,23 +712,31 @@ class FS(object): ...@@ -712,23 +712,31 @@ class FS(object):
while dirs: while dirs:
current_path = dirs.pop() current_path = dirs.pop()
paths = [] paths = []
for filename in listdir(current_path): try:
path = pathjoin(current_path, filename) for filename in listdir(current_path):
if self.isdir(path): path = pathjoin(current_path, filename)
if dir_wildcard(path): if self.isdir(path):
dirs.append(path) if dir_wildcard(path):
else: dirs.append(path)
if wildcard(filename): else:
paths.append(filename) 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) yield (current_path, paths)
elif search == "depth": elif search == "depth":
def recurse(recurse_path): def recurse(recurse_path):
for path in listdir(recurse_path, wildcard=dir_wildcard, full=True, dirs_only=True): try:
for p in recurse(path): for path in listdir(recurse_path, wildcard=dir_wildcard, full=True, dirs_only=True):
yield p 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)) yield (recurse_path, self.listdir(recurse_path, wildcard=wildcard, files_only=True))
for p in recurse(path): for p in recurse(path):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment