mirror of
https://github.com/sharkdp/fd
synced 2024-09-15 22:20:45 +00:00
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)
|
.takes_value(true)
|
||||||
.number_of_values(1),
|
.number_of_values(1),
|
||||||
)
|
)
|
||||||
|
.arg(arg("show-errors").long("show-errors"))
|
||||||
.arg(arg("pattern"))
|
.arg(arg("pattern"))
|
||||||
.arg(arg("path").multiple(true))
|
.arg(arg("path").multiple(true))
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -322,6 +323,10 @@ fn usage() -> HashMap<&'static str, Help> {
|
||||||
, "Limit results based on modification time within the duration provided:\n \
|
, "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 \
|
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");
|
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"
|
doc!(h, "search-path"
|
||||||
, "Provide paths to search as flag arguments rather than positional arguments."
|
, "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\
|
, "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>>>,
|
rx: Arc<Mutex<Receiver<WorkerResult>>>,
|
||||||
cmd: Arc<CommandTemplate>,
|
cmd: Arc<CommandTemplate>,
|
||||||
out_perm: Arc<Mutex<()>>,
|
out_perm: Arc<Mutex<()>>,
|
||||||
|
show_filesystem_errors: bool,
|
||||||
) {
|
) {
|
||||||
loop {
|
loop {
|
||||||
// Create a lock on the shared receiver for this thread.
|
// Create a lock on the shared receiver for this thread.
|
||||||
|
@ -29,7 +30,9 @@ pub fn job(
|
||||||
let value: PathBuf = match lock.recv() {
|
let value: PathBuf = match lock.recv() {
|
||||||
Ok(WorkerResult::Entry(val)) => val,
|
Ok(WorkerResult::Entry(val)) => val,
|
||||||
Ok(WorkerResult::Error(err)) => {
|
Ok(WorkerResult::Error(err)) => {
|
||||||
print_error!("{}", err);
|
if show_filesystem_errors {
|
||||||
|
print_error!("{}", err);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Err(_) => break,
|
Err(_) => break,
|
||||||
|
|
|
@ -72,4 +72,7 @@ pub struct FdOptions {
|
||||||
|
|
||||||
/// Constraints on last modification time of files
|
/// Constraints on last modification time of files
|
||||||
pub time_constraints: Vec<TimeFilter>,
|
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![]),
|
.unwrap_or_else(|| vec![]),
|
||||||
size_constraints: size_limits,
|
size_constraints: size_limits,
|
||||||
time_constraints,
|
time_constraints,
|
||||||
|
show_filesystem_errors: matches.is_present("show-errors"),
|
||||||
};
|
};
|
||||||
|
|
||||||
match RegexBuilder::new(&pattern_regex)
|
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");
|
.expect("Error: Path vector can not be empty");
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
let threads = config.threads;
|
let threads = config.threads;
|
||||||
|
let show_filesystem_errors = config.show_filesystem_errors;
|
||||||
|
|
||||||
let mut override_builder = OverrideBuilder::new(first_path_buf.as_path());
|
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);
|
let out_perm = Arc::clone(&out_perm);
|
||||||
|
|
||||||
// Spawn a job thread that will listen for and execute inputs.
|
// 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.
|
// Push the handle of the spawned thread into the vector for later joining.
|
||||||
handles.push(handle);
|
handles.push(handle);
|
||||||
|
@ -193,7 +195,9 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WorkerResult::Error(err) => {
|
WorkerResult::Error(err) => {
|
||||||
print_error!("{}", err);
|
if show_filesystem_errors {
|
||||||
|
print_error!("{}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue