Skip to content

Commit c0110c6

Browse files
committed
Ignore broken but excluded file during traversing
Walkdir's [`filter_entry()`][1] won't call the predicate if the entry is essentially an `Err` from its underyling `IntoIter`. That means Cargo hasn't had a chance to call `filter` on an entry that should be excluded but eventually return an `Err` and cause the loop to stop. For instance, a broken symlink which should bee excluded by `filter` will generate an error since `filter` closure is not called with it. The solution is calling `filter` if an error occurs with a path (because it has yet been called with that path). If it's exactly excluded, ignore the error. [1]: https://github.com/BurntSushi/walkdir/blob/abf3a15887758e0af54ebca827c7b6f8b311cb45/src/lib.rs#L1042-L1058
1 parent 52a418c commit c0110c6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/cargo/sources/path.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,11 @@ impl<'cfg> PathSource<'cfg> {
432432
self.config.shell().warn(err)?;
433433
}
434434
Err(err) => match err.path() {
435-
// If the error occurs with a path, simply recover from it.
435+
// If an error occurs with a path, filter it again.
436+
// If it is excluded, Just ignore it in this case.
437+
// See issue rust-lang/cargo#10917
438+
Some(path) if !filter(path, path.is_dir()) => {}
439+
// Otherwise, simply recover from it.
436440
// Don't worry about error skipping here, the callers would
437441
// still hit the IO error if they do access it thereafter.
438442
Some(path) => ret.push(path.to_path_buf()),

0 commit comments

Comments
 (0)