From 53a561a222f342ee36714af95d11ac5d304f46e9 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 21 Oct 2020 10:47:41 +0200 Subject: [PATCH] pass params by ref to recurse_files gets rid of the return value and moving around of the zip and decoder data avoids cloning the path prefix on every recursion Signed-off-by: Wolfgang Bumiller --- src/api2/admin/datastore.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 3cb52a4c..38f54090 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -2,7 +2,7 @@ use std::collections::{HashSet, HashMap}; use std::ffi::OsStr; use std::os::unix::ffi::OsStrExt; use std::sync::{Arc, Mutex}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::pin::Pin; use anyhow::{bail, format_err, Error}; @@ -1248,12 +1248,12 @@ fn catalog( Ok(res.into()) } -fn recurse_files( - mut zip: ZipEncoder, - mut decoder: Accessor, - prefix: PathBuf, +fn recurse_files<'a, T, W>( + zip: &'a mut ZipEncoder, + decoder: &'a mut Accessor, + prefix: &'a Path, file: FileEntry, -) -> Pin, Accessor), Error>> + Send + 'static>> +) -> Pin> + Send + 'a>> where T: Clone + pxar::accessor::ReadAt + Unpin + Send + Sync + 'static, W: tokio::io::AsyncWrite + Unpin + Send + 'static, @@ -1298,16 +1298,13 @@ where zip.add_entry::>(entry, None).await?; while let Some(entry) = readdir.next().await { let entry = entry?.decode_entry().await?; - let (zip_tmp, decoder_tmp) = - recurse_files(zip, decoder, prefix.clone(), entry).await?; - zip = zip_tmp; - decoder = decoder_tmp; + recurse_files(zip, decoder, prefix, entry).await?; } } _ => {} // ignore all else }; - Ok((zip, decoder)) + Ok(()) }) } @@ -1420,10 +1417,11 @@ fn pxar_file_download( } let channelwriter = AsyncChannelWriter::new(sender, 1024 * 1024); - let zipencoder = ZipEncoder::new(channelwriter); crate::server::spawn_internal_task(async move { - let (mut zipencoder, _) = recurse_files(zipencoder, decoder, prefix, file) + let mut zipencoder = ZipEncoder::new(channelwriter); + let mut decoder = decoder; + recurse_files(&mut zipencoder, &mut decoder, &prefix, file) .await .map_err(|err| eprintln!("error during creating of zip: {}", err))?;