diff options
author | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2010-12-20 19:10:18 +0000 |
---|---|---|
committer | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2010-12-20 19:10:18 +0000 |
commit | 1ae3b0bbc0bc8336e96992e76baa746f66416ab2 (patch) | |
tree | bde72bb2a08a7b28aed760e913acadbf8fb6d3df /fs/base.py | |
parent | e0fd44efffba7b4011e7ee7ae8bd09a682fd24db (diff) | |
download | pyfilesystem-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.py | 32 |
1 files changed, 20 insertions, 12 deletions
@@ -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): |