Skip to content
Myr

Add collection of job & thread exit codes + default to ExitCode::Error if any ExitCode::Error

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

authored by fusillicode · committed by David Peter · parent fa7d492 · Browse files · 3 files+25 added−9 removed
This commit

State

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

Diff stats

3 files+25 added−9 removed

  • other:+25 added−9 removed

3 files+25 added−9 removed

modified:src/exec/job.rs+7 added-4 removed
19 unmodified lines
20 rx: Arc<Mutex<Receiver<WorkerResult>>>,21 cmd: Arc<CommandTemplate>,22 out_perm: Arc<Mutex<()>>,23 show_filesystem_errors: bool,24) {24) -> ExitCode {25 let mut results: Vec<ExitCode> = Vec::new();26 loop {27 // Create a lock on the shared receiver for this thread.28 let lock = rx.lock().unwrap();29
9 unmodified lines
39 }40 Err(_) => break,41 };4242 // Drop the lock so that other threads can read from the the receiver.43 // Drop the lock so that other threads can read from the receiver.44 drop(lock);44 // Generate a command and execute it.45 cmd.generate_and_execute(&value, Arc::clone(&out_perm));45 // Generate a command, executes it and store its exit code.46 results.push(cmd.generate_and_execute(&value, Arc::clone(&out_perm)))47 }48 // Returns error in case of any error.49 ExitCode::error_if_any_error(results)50}5152pub fn batch(53 rx: Receiver<WorkerResult>,
14 unmodified lines
modified:src/exit_codes.rs+15 added-3 removed
5 unmodified lines
67impl Into<i32> for ExitCode {8 fn into(self) -> i32 {9 match self {10 ExitCode::Success => 0,11 ExitCode::GeneralError => 1,12 ExitCode::KilledBySigint => 130,10 Self::Success => 0,11 Self::GeneralError => 1,12 Self::KilledBySigint => 130,13 }14 }15}1617impl ExitCode {18 pub fn error_if_any_error(results: Vec<Self>) -> Self {19 if results.iter().any(|s| match s {20 Self::GeneralError => true,21 _ => false,22 }) {23 return Self::GeneralError;24 }25 Self::Success26 }27}
modified:src/walk.rs+3 added-2 removed
175 unmodified lines
176 handles.push(handle);177 }178179 // Wait for all threads to exit before exiting the program.180 let mut results: Vec<ExitCode> = Vec::new();181 for h in handles {181 h.join().unwrap();182 results.push(h.join().unwrap());183 }184184 ExitCode::Success185 ExitCode::error_if_any_error(results)186 }187 } else {188 let start = time::Instant::now();189
199 unmodified lines