Skip to content

Commit

Permalink
Prevent the invariant prefix optimization from defying the walk behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Jan 28, 2024
1 parent a7a02f6 commit 08fd2c3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/walk/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,22 @@ 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 = curr_prefix;
while let Some(parent) = curr_prefix.parent() {
if parent.is_symlink() {
last_symlink = 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.parent().unwrap_or(last_symlink).into())
}
}

Expand Down

0 comments on commit 08fd2c3

Please sign in to comment.