260924.3.4 · b3a8ff687b0d0bc4095fb23ec8dc60ff3be1308e
Take the broken symlink depth from the walker
The depth of a broken symlink was derived from its path by stripping the matching search root, because the walker did not report a depth on the errors that carry broken symlinks. ignore 0.4.28 fills that depth in, so read it from the error instead and drop the path arithmetic.
The path based version could not express one case. When two search roots overlap, the walker visits the same broken symlink once per root at a different depth each time, and both visits carry the same path, so a single path derived answer had to serve both. Searching roots a and a/b with --min-depth 2 dropped a/b/blink even though a real file in its place was kept.
reading declarations
Changes to src/dir_entry.rs. All files
@@ -11,9 +11,9 @@ use crate::filesystem::strip_current_dir; #[derive(Debug)] enum DirEntryInner { Normal(ignore::DirEntry),- // Broken symlinks are surfaced by the walker as errors that carry no depth,- // so we record the depth (relative to the search root) at creation time.- BrokenSymlink { path: PathBuf, depth: usize },+ // Broken symlinks reach us as walk errors rather than entries, so we carry+ // over the depth the walker recorded on the error.+ BrokenSymlink { path: PathBuf, depth: Option<usize> }, } #[derive(Debug)]@@ -33,7 +33,7 @@ impl DirEntry { } } - pub fn broken_symlink(path: PathBuf, depth: usize) -> Self {+ pub fn broken_symlink(path: PathBuf, depth: Option<usize>) -> Self { Self { inner: DirEntryInner::BrokenSymlink { path, depth }, metadata: OnceCell::new(),@@ -100,7 +100,7 @@ impl DirEntry { pub fn depth(&self) -> Option<usize> { match &self.inner { DirEntryInner::Normal(e) => Some(e.depth()),- DirEntryInner::BrokenSymlink { depth, .. } => Some(*depth),+ DirEntryInner::BrokenSymlink { depth, .. } => *depth, } }