Revert -X stuff

This reverts commit 91860bf682.
This commit is contained in:
Jonah Caplan 2021-10-16 14:02:44 -04:00
parent 91860bf682
commit fbc836b553
5 changed files with 16 additions and 49 deletions

View file

@ -2,10 +2,8 @@ use std::path::PathBuf;
use std::sync::mpsc::Receiver; use std::sync::mpsc::Receiver;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use crate::config::Config;
use crate::error::print_error; use crate::error::print_error;
use crate::exit_codes::{merge_exitcodes, ExitCode}; use crate::exit_codes::{merge_exitcodes, ExitCode};
use crate::filesystem::strip_current_dir;
use crate::walk::WorkerResult; use crate::walk::WorkerResult;
use super::CommandTemplate; use super::CommandTemplate;
@ -19,7 +17,6 @@ pub fn job(
out_perm: Arc<Mutex<()>>, out_perm: Arc<Mutex<()>>,
show_filesystem_errors: bool, show_filesystem_errors: bool,
buffer_output: bool, buffer_output: bool,
config: &Arc<Config>,
) -> ExitCode { ) -> ExitCode {
let mut results: Vec<ExitCode> = Vec::new(); let mut results: Vec<ExitCode> = Vec::new();
loop { loop {
@ -39,15 +36,10 @@ pub fn job(
Err(_) => break, 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 the lock so that other threads can read from the receiver.
drop(lock); drop(lock);
// Generate a command, execute it and store its exit code. // 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. // Returns error in case of any error.
merge_exitcodes(results) merge_exitcodes(results)
@ -58,25 +50,15 @@ pub fn batch(
cmd: &CommandTemplate, cmd: &CommandTemplate,
show_filesystem_errors: bool, show_filesystem_errors: bool,
buffer_output: bool, buffer_output: bool,
config: &Arc<Config>,
) -> ExitCode { ) -> ExitCode {
let paths = rx let paths = rx.iter().filter_map(|value| match value {
.iter() WorkerResult::Entry(val) => Some(val),
.filter_map(|value| match value { WorkerResult::Error(err) => {
WorkerResult::Entry(val) => Some(val), if show_filesystem_errors {
WorkerResult::Error(err) => { print_error(err.to_string());
if show_filesystem_errors {
print_error(err.to_string());
}
None
} }
}) None
.map(|m| { }
if config.no_strip { });
m
} else {
strip_current_dir(&m).to_path_buf()
}
});
cmd.generate_and_execute_batch(paths, buffer_output) cmd.generate_and_execute_batch(paths, buffer_output)
} }

View file

@ -14,6 +14,7 @@ use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use crate::exit_codes::ExitCode; use crate::exit_codes::ExitCode;
use crate::filesystem::strip_current_dir;
use self::command::execute_command; use self::command::execute_command;
use self::input::{basename, dirname, remove_extension}; use self::input::{basename, dirname, remove_extension};
@ -144,6 +145,8 @@ impl CommandTemplate {
out_perm: Arc<Mutex<()>>, out_perm: Arc<Mutex<()>>,
buffer_output: bool, buffer_output: bool,
) -> ExitCode { ) -> ExitCode {
let input = strip_current_dir(input);
let mut cmd = Command::new(self.args[0].generate(&input, self.path_separator.as_deref())); let mut cmd = Command::new(self.args[0].generate(&input, self.path_separator.as_deref()));
for arg in &self.args[1..] { for arg in &self.args[1..] {
cmd.arg(arg.generate(&input, self.path_separator.as_deref())); cmd.arg(arg.generate(&input, self.path_separator.as_deref()));
@ -175,7 +178,7 @@ impl CommandTemplate {
// A single `Tokens` is expected // A single `Tokens` is expected
// So we can directly consume the iterator once and for all // So we can directly consume the iterator once and for all
for path in &mut paths { 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; has_path = true;
} }
} else { } else {

View file

@ -376,7 +376,7 @@ fn construct_config(matches: clap::ArgMatches, pattern_regex: &str) -> Result<Co
} }
}), }),
no_strip: matches.is_present("path") || matches.is_present("search-path"), no_strip: matches.is_present("path") || matches.is_present("search-path"),
}) })
} }
fn extract_command( fn extract_command(

View file

@ -179,13 +179,7 @@ fn spawn_receiver(
// This will be set to `Some` if the `--exec` argument was supplied. // This will be set to `Some` if the `--exec` argument was supplied.
if let Some(ref cmd) = config.command { if let Some(ref cmd) = config.command {
if cmd.in_batch_mode() { if cmd.in_batch_mode() {
exec::batch( exec::batch(rx, cmd, show_filesystem_errors, enable_output_buffering)
rx,
cmd,
show_filesystem_errors,
enable_output_buffering,
&config,
)
} else { } else {
let shared_rx = Arc::new(Mutex::new(rx)); let shared_rx = Arc::new(Mutex::new(rx));
@ -197,7 +191,7 @@ fn spawn_receiver(
let rx = Arc::clone(&shared_rx); let rx = Arc::clone(&shared_rx);
let cmd = Arc::clone(cmd); let cmd = Arc::clone(cmd);
let out_perm = Arc::clone(&out_perm); let out_perm = Arc::clone(&out_perm);
let config = Arc::clone(&config);
// 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 || { let handle = thread::spawn(move || {
exec::job( exec::job(
@ -206,7 +200,6 @@ fn spawn_receiver(
out_perm, out_perm,
show_filesystem_errors, show_filesystem_errors,
enable_output_buffering, enable_output_buffering,
&config,
) )
}); });

View file

@ -1935,15 +1935,4 @@ fn test_no_strip() {
./one/two/three/directory_foo ./one/two/three/directory_foo
./symlink", ./symlink",
); );
te.assert_output(
&["c.foo", "./", "-x", "echo"],
"./one/two/c.foo
./one/two/C.Foo2",
);
te.assert_output(
&["c.foo", "./", "-X", "echo"],
"./one/two/C.Foo2 ./one/two/c.foo",
)
} }