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

fix #457: Make --exclude option follow symlinked directories #458

Merged
merged 1 commit into from
Jul 31, 2023
Merged

fix #457: Make --exclude option follow symlinked directories #458

merged 1 commit into from
Jul 31, 2023

Conversation

jeancochrane
Copy link
Contributor

@jeancochrane jeancochrane commented Jul 28, 2023

This PR updates the globbing behavior for the --exclude option in api.get_matching_paths() to rely only on glob.glob() instead of Path.glob(), the latter of which contains a bug on Python <3.13 such that it does not always follow symlinked directories correctly.

@jeancochrane jeancochrane changed the title fix #457: Make exclude option follow symlinks fix #457: Make --exclude option follow symlinks Jul 28, 2023
@jeancochrane jeancochrane changed the title fix #457: Make --exclude option follow symlinks fix #457: Make --exclude option follow symlinked directories Jul 28, 2023
Comment on lines 112 to 115
except IndexError:
# for some reason Path.glob(".") raises an index error,
# although glob.glob(".") returns ["."]
pass
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can remove this error handling block given that we're no longer calling Path.glob() at all?

# latter would be more concise, since Path.glob() does not
# resolve symlinks properly in Python <3.13
exclude_set.update(
[Path(g) for g in glob(str(exclude_root / s), recursive=True)]
Copy link
Contributor Author

@jeancochrane jeancochrane Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a bit hacky to cast the Path object to a string here, but it's the only way to get it to work with glob.glob(), which expects a string. It's probably fine, and hopefully the tests would tell us if it wasn't, but part of me is a bit nervous about the platform compatibility of this change -- It works fine on my Ubuntu machine, but I can't help being nervous that e.g. Windows may handle this string conversion incorrectly.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be safe to do it this way, but thanks for calling out this change!

@jeancochrane jeancochrane marked this pull request as ready for review July 28, 2023 22:54
Copy link
Owner

@tconbeer tconbeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job with this! Thanks so much

# latter would be more concise, since Path.glob() does not
# resolve symlinks properly in Python <3.13
exclude_set.update(
[Path(g) for g in glob(str(exclude_root / s), recursive=True)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be safe to do it this way, but thanks for calling out this change!

@tconbeer tconbeer merged commit 51fdbf7 into tconbeer:main Jul 31, 2023
@jeancochrane jeancochrane deleted the fix/#457/exclude-option-does-not-follow-symlinks branch July 31, 2023 14:50
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