From 7546e9c9976203c2ade0a30b5fb34bebf7d2a535 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 13 Apr 2022 10:27:59 +0200 Subject: [PATCH] pbs-client: pxar: avoid some vec extensions The `Components` `Iterator` has an `as_path()` method to get the remainder as a borrowed path. This is more efficient iterating and joining the components into a new `PathBuf`. Signed-off-by: Wolfgang Bumiller --- pbs-client/src/pxar/extract.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs index 61f29360..93e7d4e2 100644 --- a/pbs-client/src/pxar/extract.rs +++ b/pbs-client/src/pxar/extract.rs @@ -551,12 +551,9 @@ where .await? .ok_or(format_err!("error opening '{:?}'", path.as_ref()))?; - let mut prefix = PathBuf::new(); let mut components = file.entry().path().components(); components.next_back(); // discard last - for comp in components { - prefix.push(comp); - } + let prefix = components.as_path(); let mut tarencoder = proxmox_compression::tar::Builder::new(output); let mut hardlinks: HashMap = HashMap::new(); @@ -568,7 +565,7 @@ where let entry = entry.map_err(|err| format_err!("cannot decode entry: {}", err))?; let metadata = entry.metadata(); - let path = entry.path().strip_prefix(&prefix)?.to_path_buf(); + let path = entry.path().strip_prefix(prefix)?.to_path_buf(); match entry.kind() { EntryKind::File { .. } => { @@ -590,7 +587,7 @@ where eprintln!("adding '{}' to tar", path.display()); } - let stripped_path = match realpath.strip_prefix(&prefix) { + let stripped_path = match realpath.strip_prefix(prefix) { Ok(path) => path, Err(_) => { // outside of our tar archive, add the first occurrance to the tar @@ -717,12 +714,11 @@ where .await? .ok_or(format_err!("error opening '{:?}'", path.as_ref()))?; - let mut prefix = PathBuf::new(); - let mut components = file.entry().path().components(); - components.next_back(); // discar last - for comp in components { - prefix.push(comp); - } + let prefix = { + let mut components = file.entry().path().components(); + components.next_back(); // discar last + components.as_path().to_owned() + }; let mut zipencoder = ZipEncoder::new(output); let mut decoder = decoder;