Skip to content
Myr

feat: enable display of error messages

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

authored by psinghal20 · committed by David Peter · parent 27caa33 · Browse files · 2 files+46 added−22 removed
This commit

State

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

Diff stats

2 files+46 added−22 removed

  • other:+46 added−22 removed

2 files+46 added−22 removed

modified:src/exec/job.rs+11 added-3 removed
7 unmodified lines
89use std::path::PathBuf;10use std::sync::mpsc::Receiver;11use std::sync::{Arc, Mutex};1212use::walk::WorkerResult;13use::internal::error;14use super::CommandTemplate;1516/// An event loop that listens for inputs from the `rx` receiver. Each received input will17/// generate a command with the supplied command template. The generated command will then18/// be executed, and this process will continue until the receiver's sender has closed.18pub fn job(rx: Arc<Mutex<Receiver<PathBuf>>>, cmd: Arc<CommandTemplate>, out_perm: Arc<Mutex<()>>) {19pub fn job(rx: Arc<Mutex<Receiver<WorkerResult>>>, cmd: Arc<CommandTemplate>, out_perm: Arc<Mutex<()>>) {20 loop {21 // Create a lock on the shared receiver for this thread.22 let lock = rx.lock().unwrap();2324 // Obtain the next path from the receiver, else if the channel25 // has closed, exit from the loop26 let value: PathBuf = match lock.recv() {26 Ok(value) => value,27 Ok(value) => {28 match value {29 WorkerResult::Entry(val) => val,30 WorkerResult::Error(err) => {31 error(&format!("{}", err));32 }33 }34 },35 Err(_) => break,36 };3738 // Drop the lock so that other threads can read from the the receiver.
5 unmodified lines
modified:src/walk.rs+35 added-19 removed
34 unmodified lines
35 /// Receiver is directly printing results to the output.36 Streaming,37}3839/// The Worker threads can result in a valid entry having PathBuf or an error.40pub enum WorkerResult {41 Entry(PathBuf),42 Error(ignore::Error)43}4445/// Recursively scan the given search path for files / pathnames matching the pattern.46///47/// If the `--exec` argument was supplied, this will create a thread pool for executing48/// jobs in parallel from a given command line and the discovered paths. Otherwise, each
112 unmodified lines
161 let max_buffer_time = rx_config162 .max_buffer_time163 .unwrap_or_else(|| time::Duration::from_millis(100));164165 for worker_result in rx {166 match worker_result {159 for value in rx {160 match mode {161 ReceiverMode::Buffering => {162 buffer.push(value);167 WorkerResult::Entry(value) => {168 match mode {169 ReceiverMode::Buffering => {170 buffer.push(value);171164 // Have we reached the maximum buffer size or maximum buffering time?165 if buffer.len() > MAX_BUFFER_LENGTH166 || time::Instant::now() - start > max_buffer_time167 {168 // Flush the buffer169 for v in &buffer {170 output::print_entry(v, &rx_config, &receiver_wtq);171 }172 buffer.clear();172 // Have we reached the maximum buffer size or maximum buffering time?173 if buffer.len() > MAX_BUFFER_LENGTH174 || time::Instant::now() - start > max_buffer_time175 {176 // Flush the buffer177 for v in &buffer {178 output::print_entry(v, &rx_config, &receiver_wtq);179 }180 buffer.clear();181174 // Start streaming175 mode = ReceiverMode::Streaming;182 // Start streaming183 mode = ReceiverMode::Streaming;184 }185 }186 ReceiverMode::Streaming => {187 output::print_entry(&value, &rx_config, &receiver_wtq);188 }189 }190 }178 ReceiverMode::Streaming => {179 output::print_entry(&value, &rx_config, &receiver_wtq);191 WorkerResult::Error(err) => {192 error(&format!("{}", err));193 }194 }195 }196
21 unmodified lines
218 }219220 let entry = match entry_o {221 Ok(e) => e,209 Err(_) => return ignore::WalkState::Continue,222 Err(err) => {223 tx_thread.send(WorkerResult::Error(err)).unwrap();224 return ignore::WalkState::Continue;225 }226 };227228 if entry.depth() == 0 {229 return ignore::WalkState::Continue;
69 unmodified lines
299300 if let Some(search_str) = search_str_o {301 if pattern.is_match(&*search_str) {302 // TODO: take care of the unwrap call287 tx_thread.send(entry_path.to_owned()).unwrap()303 tx_thread.send(WorkerResult::Entry(entry_path.to_owned())).unwrap()304 }305 }306307 ignore::WalkState::Continue
14 unmodified lines