]> git.proxmox.com Git - cargo.git/commitdiff
Ignore broken but excluded file during traversing
authorWeihang Lo <me@weihanglo.tw>
Fri, 19 Aug 2022 22:30:01 +0000 (23:30 +0100)
committerWeihang Lo <me@weihanglo.tw>
Fri, 19 Aug 2022 23:56:43 +0000 (00:56 +0100)
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

src/cargo/sources/path.rs

index b371a841f3934b1ca782562d357df99e4456932e..c4cff058ba932d45ca519cb96fb598ae70e48809 100644 (file)
@@ -432,7 +432,11 @@ impl<'cfg> PathSource<'cfg> {
                     self.config.shell().warn(err)?;
                 }
                 Err(err) => match err.path() {
-                    // If the error occurs with a path, simply recover from it.
+                    // If an error occurs with a path, filter it again.
+                    // If it is excluded, Just ignore it in this case.
+                    // See issue rust-lang/cargo#10917
+                    Some(path) if !filter(path, path.is_dir()) => {}
+                    // Otherwise, simply recover from it.
                     // Don't worry about error skipping here, the callers would
                     // still hit the IO error if they do access it thereafter.
                     Some(path) => ret.push(path.to_path_buf()),