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 <w.bumiller@proxmox.com>
This commit is contained in:
parent
0bb4036f25
commit
7546e9c997
|
@ -551,12 +551,9 @@ where
|
||||||
.await?
|
.await?
|
||||||
.ok_or(format_err!("error opening '{:?}'", path.as_ref()))?;
|
.ok_or(format_err!("error opening '{:?}'", path.as_ref()))?;
|
||||||
|
|
||||||
let mut prefix = PathBuf::new();
|
|
||||||
let mut components = file.entry().path().components();
|
let mut components = file.entry().path().components();
|
||||||
components.next_back(); // discard last
|
components.next_back(); // discard last
|
||||||
for comp in components {
|
let prefix = components.as_path();
|
||||||
prefix.push(comp);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut tarencoder = proxmox_compression::tar::Builder::new(output);
|
let mut tarencoder = proxmox_compression::tar::Builder::new(output);
|
||||||
let mut hardlinks: HashMap<PathBuf, PathBuf> = HashMap::new();
|
let mut hardlinks: HashMap<PathBuf, PathBuf> = HashMap::new();
|
||||||
|
@ -568,7 +565,7 @@ where
|
||||||
let entry = entry.map_err(|err| format_err!("cannot decode entry: {}", err))?;
|
let entry = entry.map_err(|err| format_err!("cannot decode entry: {}", err))?;
|
||||||
|
|
||||||
let metadata = entry.metadata();
|
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() {
|
match entry.kind() {
|
||||||
EntryKind::File { .. } => {
|
EntryKind::File { .. } => {
|
||||||
|
@ -590,7 +587,7 @@ where
|
||||||
eprintln!("adding '{}' to tar", path.display());
|
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,
|
Ok(path) => path,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// outside of our tar archive, add the first occurrance to the tar
|
// outside of our tar archive, add the first occurrance to the tar
|
||||||
|
@ -717,12 +714,11 @@ where
|
||||||
.await?
|
.await?
|
||||||
.ok_or(format_err!("error opening '{:?}'", path.as_ref()))?;
|
.ok_or(format_err!("error opening '{:?}'", path.as_ref()))?;
|
||||||
|
|
||||||
let mut prefix = PathBuf::new();
|
let prefix = {
|
||||||
let mut components = file.entry().path().components();
|
let mut components = file.entry().path().components();
|
||||||
components.next_back(); // discar last
|
components.next_back(); // discar last
|
||||||
for comp in components {
|
components.as_path().to_owned()
|
||||||
prefix.push(comp);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
let mut zipencoder = ZipEncoder::new(output);
|
let mut zipencoder = ZipEncoder::new(output);
|
||||||
let mut decoder = decoder;
|
let mut decoder = decoder;
|
||||||
|
|
Loading…
Reference in New Issue