From 22dbed0545d1159ae9b0e68f3b59641e334d8ef7 Mon Sep 17 00:00:00 2001 From: Jonathan Goren Date: Tue, 30 Nov 2021 09:52:39 +0200 Subject: [PATCH] convert to path instead of cloning in batch exec update changelog --- CHANGELOG.md | 2 +- src/dir_entry.rs | 7 +++++++ src/exec/job.rs | 28 +++++++++++++++++----------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec1aeef..7431104 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/dir_entry.rs b/src/dir_entry.rs index 7d78e2e..6eae14a 100644 --- a/src/dir_entry.rs +++ b/src/dir_entry.rs @@ -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 { match &self.inner { DirEntryInner::Normal(e) => e.file_type(), diff --git a/src/exec/job.rs b/src/exec/job.rs index 6548716..77cff7c 100644 --- a/src/exec/job.rs +++ b/src/exec/job.rs @@ -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);