mirror of https://github.com/sharkdp/fd.git
Add collection of job & thread exit codes + default to ExitCode::Error if any ExitCode::Error
This commit is contained in:
parent
fa7d49282b
commit
7213f5a88e
|
@ -21,7 +21,8 @@ pub fn job(
|
||||||
cmd: Arc<CommandTemplate>,
|
cmd: Arc<CommandTemplate>,
|
||||||
out_perm: Arc<Mutex<()>>,
|
out_perm: Arc<Mutex<()>>,
|
||||||
show_filesystem_errors: bool,
|
show_filesystem_errors: bool,
|
||||||
) {
|
) -> ExitCode {
|
||||||
|
let mut results: Vec<ExitCode> = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
// Create a lock on the shared receiver for this thread.
|
// Create a lock on the shared receiver for this thread.
|
||||||
let lock = rx.lock().unwrap();
|
let lock = rx.lock().unwrap();
|
||||||
|
@ -39,11 +40,13 @@ pub fn job(
|
||||||
Err(_) => break,
|
Err(_) => break,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Drop the lock so that other threads can read from the the receiver.
|
// Drop the lock so that other threads can read from the receiver.
|
||||||
drop(lock);
|
drop(lock);
|
||||||
// Generate a command and execute it.
|
// Generate a command, executes it and store its exit code.
|
||||||
cmd.generate_and_execute(&value, Arc::clone(&out_perm));
|
results.push(cmd.generate_and_execute(&value, Arc::clone(&out_perm)))
|
||||||
}
|
}
|
||||||
|
// Returns error in case of any error.
|
||||||
|
ExitCode::error_if_any_error(results)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn batch(
|
pub fn batch(
|
||||||
|
|
|
@ -7,9 +7,21 @@ pub enum ExitCode {
|
||||||
impl Into<i32> for ExitCode {
|
impl Into<i32> for ExitCode {
|
||||||
fn into(self) -> i32 {
|
fn into(self) -> i32 {
|
||||||
match self {
|
match self {
|
||||||
ExitCode::Success => 0,
|
Self::Success => 0,
|
||||||
ExitCode::GeneralError => 1,
|
Self::GeneralError => 1,
|
||||||
ExitCode::KilledBySigint => 130,
|
Self::KilledBySigint => 130,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ExitCode {
|
||||||
|
pub fn error_if_any_error(results: Vec<Self>) -> Self {
|
||||||
|
if results.iter().any(|s| match s {
|
||||||
|
Self::GeneralError => true,
|
||||||
|
_ => false,
|
||||||
|
}) {
|
||||||
|
return Self::GeneralError;
|
||||||
|
}
|
||||||
|
Self::Success
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -177,11 +177,12 @@ fn spawn_receiver(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for all threads to exit before exiting the program.
|
// Wait for all threads to exit before exiting the program.
|
||||||
|
let mut results: Vec<ExitCode> = Vec::new();
|
||||||
for h in handles {
|
for h in handles {
|
||||||
h.join().unwrap();
|
results.push(h.join().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
ExitCode::Success
|
ExitCode::error_if_any_error(results)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let start = time::Instant::now();
|
let start = time::Instant::now();
|
||||||
|
|
Loading…
Reference in New Issue