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

Prevent the invariant prefix optimization from defying the walk behavior #57

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/walk/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,27 @@ impl<'t> Glob<'t> {
None
}
else {
Some(prefix.into())
// here, we don't know if the glob will be walked with or without symlinks,
// so we need to ensure that the invariant prefix optimisation doesn't cross a
// symlink todo: `anchor` knows nothing about the walk behaviour. if it did, we
// could probably skip this conditionally for a small perf bonus
let prefix: PathBuf = prefix.into();
let mut curr_prefix = prefix.as_path();
let mut last_symlink = None;
while let Some(parent) = curr_prefix.parent() {
if parent.is_symlink() {
last_symlink = Some(parent);
}
curr_prefix = parent;
}
// we found the last symlink, but we need the chance to
// filter it, so take the parent one more time
Some(
last_symlink
.and_then(Path::parent)
.map(Into::into)
.unwrap_or(prefix),
)
}
}

Expand Down
Loading