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 glob expansion that includes broken symlinks #1567

Merged

Conversation

krader1961
Copy link
Contributor

Glob expansion should use os.Lstat rather than os.Stat so that broken
symlinks don't stop glob expansion. It's not the place of glob expansion
to decide if a particular path is good.

The symlink test cases and logic were borrowed from
pkg/mods/path/path_test.go.

Fixes #1240

@krader1961 krader1961 force-pushed the issue-1240-wildcard-expansion-bad-symlink branch from 3ca727a to 1433fd1 Compare June 27, 2022 02:04
Glob expansion should use os.Lstat rather than os.Stat so that broken
symlinks don't stop glob expansion. It's not the place of glob expansion
to decide if a particular path is good.

The symlink test cases and logic were borrowed from
pkg/mods/path/path_test.go.

Fixes elves#1240
@krader1961 krader1961 force-pushed the issue-1240-wildcard-expansion-bad-symlink branch from 1433fd1 to c0ab3ca Compare June 29, 2022 01:27
Comment on lines +94 to +96
// Creating symlinks requires a special permission on Windows. If
// the user doesn't have that permission, just skip the whole test.
t.Skip(err)
Copy link
Member

Choose a reason for hiding this comment

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

Skipping the entire test makes sense in the TestPath_Symlink function this is borrowed from, because that entire test is about symlinks. It makes much less sense here, it makes a large part of the globbing code untested on Windows. A better strategy is to just create the symlinks as ordinary files on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I would argue that both sets of tests should fail if unable to create a symlink on Windows. The CI environment should always have that capability enabled. And anyone running these tests on their local system should also have the capability enabled. The question is whether, and how, to test the behavior on Windows when the symlink capability isn't enabled.

Comment on lines +24 to +25
- Glob expansion that includes broken symlinks no longer short-circuits the
expansion ([#1240](https://b.elv.sh/1240)).
Copy link
Member

Choose a reason for hiding this comment

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

This is a fix but it's also a breaking change - symlinks to directories will now be treated as files, not directories. This breaking change is fine for me - among other things it avoids infinite recursions when expanding ** symlinks introduce loops in the FS tree. But it should be documented as such.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another good point but the existing behavior is flat out wrong and it's unclear how to document the change in behavior.

@xiaq xiaq merged commit a72224d into elves:master Aug 28, 2022
xiaq added a commit that referenced this pull request Aug 28, 2022
- Don't skip glob_test on Windows.

- Document the change as a breaking change.
@krader1961 krader1961 deleted the issue-1240-wildcard-expansion-bad-symlink branch August 29, 2022 04:00
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.

Broken symlink causes wildcard matching to fail
2 participants