diff --git a/src/exec/job.rs b/src/exec/job.rs index d940707..83abf1a 100644 --- a/src/exec/job.rs +++ b/src/exec/job.rs @@ -2,10 +2,8 @@ use std::path::PathBuf; use std::sync::mpsc::Receiver; use std::sync::{Arc, Mutex}; -use crate::config::Config; use crate::error::print_error; use crate::exit_codes::{merge_exitcodes, ExitCode}; -use crate::filesystem::strip_current_dir; use crate::walk::WorkerResult; use super::CommandTemplate; @@ -19,7 +17,6 @@ pub fn job( out_perm: Arc>, show_filesystem_errors: bool, buffer_output: bool, - config: &Arc, ) -> ExitCode { let mut results: Vec = Vec::new(); loop { @@ -39,15 +36,10 @@ pub fn job( Err(_) => break, }; - let path = if config.no_strip { - value - } else { - strip_current_dir(&value).to_path_buf() - }; // Drop the lock so that other threads can read from the receiver. drop(lock); // Generate a command, execute it and store its exit code. - results.push(cmd.generate_and_execute(&path, Arc::clone(&out_perm), buffer_output)) + results.push(cmd.generate_and_execute(&value, Arc::clone(&out_perm), buffer_output)) } // Returns error in case of any error. merge_exitcodes(results) @@ -58,25 +50,15 @@ pub fn batch( cmd: &CommandTemplate, show_filesystem_errors: bool, buffer_output: bool, - config: &Arc, ) -> ExitCode { - let paths = rx - .iter() - .filter_map(|value| match value { - WorkerResult::Entry(val) => Some(val), - WorkerResult::Error(err) => { - if show_filesystem_errors { - print_error(err.to_string()); - } - None + let paths = rx.iter().filter_map(|value| match value { + WorkerResult::Entry(val) => Some(val), + WorkerResult::Error(err) => { + if show_filesystem_errors { + print_error(err.to_string()); } - }) - .map(|m| { - if config.no_strip { - m - } else { - strip_current_dir(&m).to_path_buf() - } - }); + None + } + }); cmd.generate_and_execute_batch(paths, buffer_output) } diff --git a/src/exec/mod.rs b/src/exec/mod.rs index 15e1ae5..a364e86 100644 --- a/src/exec/mod.rs +++ b/src/exec/mod.rs @@ -14,6 +14,7 @@ use lazy_static::lazy_static; use regex::Regex; use crate::exit_codes::ExitCode; +use crate::filesystem::strip_current_dir; use self::command::execute_command; use self::input::{basename, dirname, remove_extension}; @@ -144,6 +145,8 @@ impl CommandTemplate { out_perm: Arc>, buffer_output: bool, ) -> ExitCode { + let input = strip_current_dir(input); + let mut cmd = Command::new(self.args[0].generate(&input, self.path_separator.as_deref())); for arg in &self.args[1..] { cmd.arg(arg.generate(&input, self.path_separator.as_deref())); @@ -175,7 +178,7 @@ impl CommandTemplate { // A single `Tokens` is expected // So we can directly consume the iterator once and for all for path in &mut paths { - cmd.arg(arg.generate(path, self.path_separator.as_deref())); + cmd.arg(arg.generate(strip_current_dir(path), self.path_separator.as_deref())); has_path = true; } } else { diff --git a/src/main.rs b/src/main.rs index e9ad6f7..47e68bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -376,7 +376,7 @@ fn construct_config(matches: clap::ArgMatches, pattern_regex: &str) -> Result