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::{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<Mutex<()>>,
show_filesystem_errors: bool,
buffer_output: bool,
config: &Arc<Config>,
) -> ExitCode {
let mut results: Vec<ExitCode> = 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,11 +50,8 @@ pub fn batch(
cmd: &CommandTemplate,
show_filesystem_errors: bool,
buffer_output: bool,
config: &Arc<Config>,
) -> ExitCode {
let paths = rx
.iter()
.filter_map(|value| match value {
let paths = rx.iter().filter_map(|value| match value {
WorkerResult::Entry(val) => Some(val),
WorkerResult::Error(err) => {
if show_filesystem_errors {
@ -70,13 +59,6 @@ pub fn batch(
}
None
}
})
.map(|m| {
if config.no_strip {
m
} else {
strip_current_dir(&m).to_path_buf()
}
});
cmd.generate_and_execute_batch(paths, buffer_output)
}

View file

@ -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<Mutex<()>>,
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 {

View file

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

View file

@ -1935,15 +1935,4 @@ fn test_no_strip() {
./one/two/three/directory_foo
./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",
)
}