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

Robustly determine parent directories #20

Merged
merged 2 commits into from
Mar 5, 2023
Merged

Conversation

jadoc
Copy link
Contributor

@jadoc jadoc commented Mar 2, 2023

It's not safe to assume path separator or root character when walking up through parent directories. This can lead to an infinite loop in some cases and on some platforms. It's better to stop walking when the path is no longer getting shorter.

In this case, I simply break out of the loop when the old path and current path are the same. Alternatively, I could count characters and make sure it decrements on each iteration.

@jadoc jadoc changed the title Robustly determine parent directory Robustly determine parent directories Mar 2, 2023
@jadoc jadoc marked this pull request as ready for review March 2, 2023 05:39
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.

2 participants