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 <w.bumiller@proxmox.com>
This commit is contained in:
parent
e832860a3c
commit
53a561a222
|
@ -2,7 +2,7 @@ use std::collections::{HashSet, HashMap};
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
|
@ -1248,12 +1248,12 @@ fn catalog(
|
||||||
Ok(res.into())
|
Ok(res.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recurse_files<T, W>(
|
fn recurse_files<'a, T, W>(
|
||||||
mut zip: ZipEncoder<W>,
|
zip: &'a mut ZipEncoder<W>,
|
||||||
mut decoder: Accessor<T>,
|
decoder: &'a mut Accessor<T>,
|
||||||
prefix: PathBuf,
|
prefix: &'a Path,
|
||||||
file: FileEntry<T>,
|
file: FileEntry<T>,
|
||||||
) -> Pin<Box<dyn Future<Output = Result<(ZipEncoder<W>, Accessor<T>), Error>> + Send + 'static>>
|
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>
|
||||||
where
|
where
|
||||||
T: Clone + pxar::accessor::ReadAt + Unpin + Send + Sync + 'static,
|
T: Clone + pxar::accessor::ReadAt + Unpin + Send + Sync + 'static,
|
||||||
W: tokio::io::AsyncWrite + Unpin + Send + 'static,
|
W: tokio::io::AsyncWrite + Unpin + Send + 'static,
|
||||||
|
@ -1298,16 +1298,13 @@ where
|
||||||
zip.add_entry::<FileContents<T>>(entry, None).await?;
|
zip.add_entry::<FileContents<T>>(entry, None).await?;
|
||||||
while let Some(entry) = readdir.next().await {
|
while let Some(entry) = readdir.next().await {
|
||||||
let entry = entry?.decode_entry().await?;
|
let entry = entry?.decode_entry().await?;
|
||||||
let (zip_tmp, decoder_tmp) =
|
recurse_files(zip, decoder, prefix, entry).await?;
|
||||||
recurse_files(zip, decoder, prefix.clone(), entry).await?;
|
|
||||||
zip = zip_tmp;
|
|
||||||
decoder = decoder_tmp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {} // ignore all else
|
_ => {} // ignore all else
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((zip, decoder))
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1420,10 +1417,11 @@ fn pxar_file_download(
|
||||||
}
|
}
|
||||||
|
|
||||||
let channelwriter = AsyncChannelWriter::new(sender, 1024 * 1024);
|
let channelwriter = AsyncChannelWriter::new(sender, 1024 * 1024);
|
||||||
let zipencoder = ZipEncoder::new(channelwriter);
|
|
||||||
|
|
||||||
crate::server::spawn_internal_task(async move {
|
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
|
.await
|
||||||
.map_err(|err| eprintln!("error during creating of zip: {}", err))?;
|
.map_err(|err| eprintln!("error during creating of zip: {}", err))?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue