mirror of https://github.com/sharkdp/fd.git
Print errors when --verbose is set
This commit is contained in:
parent
f7a96bd980
commit
095bad550f
|
@ -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: <NUM>d <NUM>h <NUM>m <NUM>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\
|
||||
|
|
|
@ -19,6 +19,7 @@ pub fn job(
|
|||
rx: Arc<Mutex<Receiver<WorkerResult>>>,
|
||||
cmd: Arc<CommandTemplate>,
|
||||
out_perm: Arc<Mutex<()>>,
|
||||
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,
|
||||
|
|
|
@ -72,4 +72,7 @@ pub struct FdOptions {
|
|||
|
||||
/// Constraints on last modification time of files
|
||||
pub time_constraints: Vec<TimeFilter>,
|
||||
|
||||
/// Whether or not to display filesystem errors
|
||||
pub show_filesystem_errors: bool,
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -55,6 +55,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {
|
|||
.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<Regex>, config: Arc<FdOptions>) {
|
|||
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<Regex>, config: Arc<FdOptions>) {
|
|||
}
|
||||
}
|
||||
WorkerResult::Error(err) => {
|
||||
print_error!("{}", err);
|
||||
if show_filesystem_errors {
|
||||
print_error!("{}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue