fix(archive): return result in list_archive functions

This commit is contained in:
ttyS3 2024-09-06 15:43:11 +00:00 committed by João Marcos
parent 39cef75dfe
commit 56f69e19a3
3 changed files with 7 additions and 7 deletions

View File

@ -54,7 +54,7 @@ pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path, quiet: bool)
/// List contents of `archive`, returning a vector of archive entries
pub fn list_archive(
mut archive: tar::Archive<impl Read + Send + 'static>,
) -> impl Iterator<Item = crate::Result<FileInArchive>> {
) -> crate::Result<impl Iterator<Item = crate::Result<FileInArchive>>> {
struct Files(Receiver<crate::Result<FileInArchive>>);
impl Iterator for Files {
type Item = crate::Result<FileInArchive>;
@ -77,7 +77,7 @@ pub fn list_archive(
}
});
Files(rx)
Ok(Files(rx))
}
/// Compresses the archives given by `input_filenames` into the file given previously to `writer`.

View File

@ -106,7 +106,7 @@ where
pub fn list_archive<R>(
mut archive: ZipArchive<R>,
password: Option<&[u8]>,
) -> impl Iterator<Item = crate::Result<FileInArchive>>
) -> crate::Result<impl Iterator<Item = crate::Result<FileInArchive>>>
where
R: Read + Seek + Send + 'static,
{
@ -146,7 +146,7 @@ where
}
});
Files(rx)
Ok(Files(rx))
}
/// Compresses the archives given by `input_filenames` into the file given previously to `writer`.

View File

@ -34,7 +34,7 @@ pub fn list_archive_contents(
// Any other Zip decompression done can take up the whole RAM and freeze ouch.
if let &[Zip] = formats.as_slice() {
let zip_archive = zip::ZipArchive::new(reader)?;
let files = crate::archive::zip::list_archive(zip_archive, password);
let files = crate::archive::zip::list_archive(zip_archive, password)?;
list::list_files(archive_path, files, list_options)?;
return Ok(());
@ -64,7 +64,7 @@ pub fn list_archive_contents(
}
let files: Box<dyn Iterator<Item = crate::Result<FileInArchive>>> = match formats[0] {
Tar => Box::new(crate::archive::tar::list_archive(tar::Archive::new(reader))),
Tar => Box::new(crate::archive::tar::list_archive(tar::Archive::new(reader))?),
Zip => {
if formats.len() > 1 {
// Locking necessary to guarantee that warning and question
@ -81,7 +81,7 @@ pub fn list_archive_contents(
io::copy(&mut reader, &mut vec)?;
let zip_archive = zip::ZipArchive::new(io::Cursor::new(vec))?;
Box::new(crate::archive::zip::list_archive(zip_archive, password))
Box::new(crate::archive::zip::list_archive(zip_archive, password)?)
}
#[cfg(feature = "unrar")]
Rar => {