From 095bad550f5ff131c4eb8279775a94bf0e9562df Mon Sep 17 00:00:00 2001 From: Park Juhyung Date: Mon, 22 Oct 2018 21:20:08 +0900 Subject: [PATCH] Print errors when --verbose is set --- src/app.rs | 5 +++++ src/exec/job.rs | 5 ++++- src/internal/opts.rs | 3 +++ src/main.rs | 1 + src/walk.rs | 8 ++++++-- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/app.rs b/src/app.rs index e6146f8..d8fe4bf 100644 --- a/src/app.rs +++ b/src/app.rs @@ -181,6 +181,7 @@ pub fn build_app() -> App<'static, 'static> { .takes_value(true) .number_of_values(1), ) + .arg(arg("show-errors").long("show-errors")) .arg(arg("pattern")) .arg(arg("path").multiple(true)) .arg( @@ -322,6 +323,10 @@ fn usage() -> HashMap<&'static str, Help> { , "Limit results based on modification time within the duration provided:\n \ using a duration: d h m s (e.g. 10h, 1d, 35min...)\n \ or a date and time: YYYY-MM-DD HH:MM:SS"); + doc!(h, "show-errors" + , "Enable display of filesystem errors" + , "Enable the display of filesystem errors for situations such as insufficient permissions \ + or dead symlinks."); doc!(h, "search-path" , "Provide paths to search as flag arguments rather than positional arguments." , "Provide paths to search as flag arguments, preventing the usage of any positional `path` arugments.\n\ diff --git a/src/exec/job.rs b/src/exec/job.rs index 069e141..51361d3 100644 --- a/src/exec/job.rs +++ b/src/exec/job.rs @@ -19,6 +19,7 @@ pub fn job( rx: Arc>>, cmd: Arc, out_perm: Arc>, + show_filesystem_errors: bool, ) { loop { // Create a lock on the shared receiver for this thread. @@ -29,7 +30,9 @@ pub fn job( let value: PathBuf = match lock.recv() { Ok(WorkerResult::Entry(val)) => val, Ok(WorkerResult::Error(err)) => { - print_error!("{}", err); + if show_filesystem_errors { + print_error!("{}", err); + } continue; } Err(_) => break, diff --git a/src/internal/opts.rs b/src/internal/opts.rs index c840a58..529935b 100644 --- a/src/internal/opts.rs +++ b/src/internal/opts.rs @@ -72,4 +72,7 @@ pub struct FdOptions { /// Constraints on last modification time of files pub time_constraints: Vec, + + /// Whether or not to display filesystem errors + pub show_filesystem_errors: bool, } diff --git a/src/main.rs b/src/main.rs index 3807da6..52c8323 100644 --- a/src/main.rs +++ b/src/main.rs @@ -253,6 +253,7 @@ fn main() { .unwrap_or_else(|| vec![]), size_constraints: size_limits, time_constraints, + show_filesystem_errors: matches.is_present("show-errors"), }; match RegexBuilder::new(&pattern_regex) diff --git a/src/walk.rs b/src/walk.rs index 7aaa4c7..ab3da7f 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -55,6 +55,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) { .expect("Error: Path vector can not be empty"); let (tx, rx) = channel(); let threads = config.threads; + let show_filesystem_errors = config.show_filesystem_errors; let mut override_builder = OverrideBuilder::new(first_path_buf.as_path()); @@ -143,7 +144,8 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) { let out_perm = Arc::clone(&out_perm); // Spawn a job thread that will listen for and execute inputs. - let handle = thread::spawn(move || exec::job(rx, cmd, out_perm)); + let handle = + thread::spawn(move || exec::job(rx, cmd, out_perm, show_filesystem_errors)); // Push the handle of the spawned thread into the vector for later joining. handles.push(handle); @@ -193,7 +195,9 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) { } } WorkerResult::Error(err) => { - print_error!("{}", err); + if show_filesystem_errors { + print_error!("{}", err); + } } } }