Skip to content

Fix recursion in the filesystem example - #239

Open
alan-divd wants to merge 1 commit into
fox-it:mainfrom
alan-divd:fix/examples-filesystem-recursion
Open

alan-divd wants to merge 1 commit into
fox-it:mainfrom
alan-divd:fix/examples-filesystem-recursion

Conversation

@alan-divd

Copy link
Copy Markdown

Summary

The example walks directories through self.iter(), which resolves each path
before recursing. Resolving follows symlinks, so a symlink pointing at one of
its own parents makes the walk descend the same tree over and over instead of
terminating.

Recurse through self._iter() instead, which skips the resolve step. The
entries come from iterdir() and are already known to exist, so resolving
them again was redundant regardless.

Also drops the path.joinpath(i), since iterdir() already yields full
paths.

Fixes #234

Test plan

  • tox run -e py3 passes (518 passed)
  • Walked a directory containing a symlink to its own parent. Before the
    change the walk repeats the same two paths indefinitely and never
    reaches the regular file next to the symlink; after it, the walk
    terminates and records the symlink as a link with its target

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filesystem example can recurse indefinitely on symlinks

1 participant