Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scandir_recrusive edge cases #19

Open
loqusion opened this issue Dec 31, 2023 · 0 comments
Open

scandir_recrusive edge cases #19

loqusion opened this issue Dec 31, 2023 · 0 comments
Labels
wontfix This will not be worked on

Comments

@loqusion
Copy link
Owner

loqusion commented Dec 31, 2023

scandir_recursive is used to find shader files in one's shader directory. It has various issues that will probably only occur for less than 0.1% of users:

  • It should find and return files higher up the directory tree first via breadth-first search, but instead it does a reverse pre-order depth-first search. This can have various performance and resource usage implications in niche situations.
  • It doesn't properly handle cases where a symlink to a directory higher in the tree (e.g. a node is its own ancestor) causes an infinite loop which only breaks due to max_depth.

def scandir_recursive(
path: GenericPath[AnyStr], *, max_depth: int
) -> Iterator[os.DirEntry[AnyStr]]:
assert max_depth >= 0
dir_stack = []
with os.scandir(path) as it:
for direntry in it:
if not direntry.is_dir():
yield direntry
elif max_depth > 0:
dir_stack.append(direntry)
while dir_stack:
yield from scandir_recursive(dir_stack.pop(), max_depth=max_depth - 1)

@loqusion loqusion added bug Something isn't working wontfix This will not be worked on and removed bug Something isn't working labels Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant