Skip to content

Commit

Permalink
enh: handle PermissionError when building directory tree
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Nov 29, 2023
1 parent 45a9833 commit 0512f10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
@@ -1,6 +1,7 @@
0.6.0
- feat: generalize GUI to use all recipes
- enh: compute file hash while copying, avoiding reading data twice
- enh: handle PermissionError when building directory tree
- ref: migrate from pkg_resources to importlib.resources
- ref: unify input and output tree widget with one base class
0.5.2
Expand Down
17 changes: 13 additions & 4 deletions mpl_data_cast/path_tree.py
Expand Up @@ -40,10 +40,19 @@ def __init__(self, path: pathlib.Path, depth_limit: int = 8):
self.depth_limit = depth_limit
self.children = {}

for file_obj in self.tree_root.iterdir():
if file_obj.is_dir() and self.depth_limit > 1:
self.children[file_obj.name] = PathTree(file_obj,
self.depth_limit - 1)
tree_iterator = self.tree_root.iterdir()
while True:
try:
file_obj = next(tree_iterator)
except StopIteration:
break
except PermissionError:
# Windows might encounter this.
pass
else:
if file_obj.is_dir() and self.depth_limit > 1:
self.children[file_obj.name] = \
PathTree(file_obj, self.depth_limit - 1)
self.list_child_dirs = []
if self.depth_limit == 1:
# in case we are in the "deepest" PathTree, only make a list of
Expand Down

0 comments on commit 0512f10

Please sign in to comment.