Skip to content
Myr

walk: catch ignore NotFound error in the case of a broken symlink

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Milligan · committed by David Peter · parent 06434f2 · Browse files · 1 file+39 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+39 added−3 removed

  • other:+39 added−3 removed

1 file+39 added−3 removed

modified:src/walk.rs+39 added-3 removed
11 unmodified lines
12use crate::internal::{opts::FdOptions, osstr_to_bytes, MAX_BUFFER_LENGTH};13use crate::output;1415use std::borrow::Cow;16use std::convert::TryFrom;17use std::error::Error;18use std::ffi::OsStr;19use std::fs;20use std::io;21use std::path::PathBuf;22use std::process;23use std::sync::atomic::{AtomicBool, Ordering};
21 unmodified lines
45 Entry(PathBuf),46 Error(ignore::Error),47}4849/// Converts a WorkerResult to a PathBuf. This is required as in some cases,50/// the underlying `ignore` libary will return an error when we actually51/// still want to show the path.52///53/// Currently, the cases supported are:54/// - a broken symlink should still be found and the path returned55impl TryFrom<WorkerResult> for PathBuf {56 type Error = ignore::Error;5758 fn try_from(worker_result: WorkerResult) -> Result<PathBuf, Self::Error> {59 match worker_result {60 WorkerResult::Entry(value) => return Ok(value),61 WorkerResult::Error(err) => {62 if let ignore::Error::WithPath {63 path,64 err: path_err,65 } = &err66 {67 if let ignore::Error::Io(io_err) = &**path_err {68 if io_err.kind() == io::ErrorKind::NotFound {69 if let Ok(metadata) = fs::symlink_metadata(&path) {70 if metadata.file_type().is_symlink() {71 return Ok(path.to_path_buf());72 }73 }74 }75 }76 }77 return Err(err);78 }79 }80 }81}8283/// Recursively scan the given search path for files / pathnames matching the pattern.84///85/// If the `--exec` argument was supplied, this will create a thread pool for executing86/// jobs in parallel from a given command line and the discovered paths. Otherwise, each
149 unmodified lines
236 let stdout = io::stdout();237 let mut stdout = stdout.lock();238239 for worker_result in rx {204 match worker_result {205 WorkerResult::Entry(value) => {240 match PathBuf::try_from(worker_result) {241 Ok(value) => {242 match mode {243 ReceiverMode::Buffering => {244 buffer.push(value);245
20 unmodified lines
266 output::print_entry(&mut stdout, &value, &config, &wants_to_quit);267 }268 }269 }234 WorkerResult::Error(err) => {270 Err(err) => {271 if show_filesystem_errors {272 print_error!("{}", err);273 }274 }
150 unmodified lines