convert to path instead of cloning in batch exec

update changelog
This commit is contained in:
Jonathan Goren 2021-11-30 09:52:39 +02:00
parent 3dc61b5f28
commit 22dbed0545
3 changed files with 25 additions and 12 deletions

View File

@ -8,6 +8,7 @@
## Changes
- Directories are now printed with an additional path separator at the end: `foo/bar/`
## Other
@ -49,7 +50,6 @@
## Changes
- Directories are now printed with an additional path separator at the end: `foo/bar/`
- Apply custom `--path-separator` to commands run with `--exec(-batch)` and `--list-details`, see #697 (@aswild)
## Other

View File

@ -37,6 +37,13 @@ impl DirEntry {
}
}
pub fn into_path(self) -> PathBuf {
match self.inner {
DirEntryInner::Normal(e) => e.into_path(),
DirEntryInner::BrokenSymlink(p) => p,
}
}
pub fn file_type(&self) -> Option<FileType> {
match &self.inner {
DirEntryInner::Normal(e) => e.file_type(),

View File

@ -26,8 +26,8 @@ pub fn job(
// Obtain the next result from the receiver, else if the channel
// has closed, exit from the loop
let value: DirEntry = match lock.recv() {
Ok(WorkerResult::Entry(val)) => val,
let dir_entry: DirEntry = match lock.recv() {
Ok(WorkerResult::Entry(dir_entry)) => dir_entry,
Ok(WorkerResult::Error(err)) => {
if show_filesystem_errors {
print_error(err.to_string());
@ -40,7 +40,11 @@ pub fn job(
// 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(value.path(), Arc::clone(&out_perm), buffer_output))
results.push(cmd.generate_and_execute(
dir_entry.path(),
Arc::clone(&out_perm),
buffer_output,
))
}
// Returns error in case of any error.
merge_exitcodes(results)
@ -53,15 +57,17 @@ pub fn batch(
buffer_output: bool,
limit: usize,
) -> ExitCode {
let paths = rx.iter().filter_map(|value| match value {
WorkerResult::Entry(val) => Some(val.path().to_owned()),
WorkerResult::Error(err) => {
if show_filesystem_errors {
print_error(err.to_string());
let paths = rx
.into_iter()
.filter_map(|worker_result| match worker_result {
WorkerResult::Entry(dir_entry) => Some(dir_entry.into_path()),
WorkerResult::Error(err) => {
if show_filesystem_errors {
print_error(err.to_string());
}
None
}
None
}
});
});
if limit == 0 {
// no limit
return cmd.generate_and_execute_batch(paths, buffer_output);