From 3bb0e57ed46828e7d9245a0d9f11d489097e07f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Thu, 5 Jan 2023 15:52:21 -0300 Subject: [PATCH] Stop keeping track of the names of unpacked files --- src/archive/tar.rs | 7 +++---- src/archive/zip.rs | 6 +++--- src/commands/decompress.rs | 12 ++++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/archive/tar.rs b/src/archive/tar.rs index c87524d..ff9d3e7 100644 --- a/src/archive/tar.rs +++ b/src/archive/tar.rs @@ -22,15 +22,14 @@ use crate::{ /// Unpacks the archive given by `archive` into the folder given by `into`. /// Assumes that output_folder is empty -pub fn unpack_archive(reader: Box, output_folder: &Path, quiet: bool) -> crate::Result> { +pub fn unpack_archive(reader: Box, output_folder: &Path, quiet: bool) -> crate::Result { assert!(output_folder.read_dir().expect("dir exists").count() == 0); let mut archive = tar::Archive::new(reader); - let mut files_unpacked = vec![]; + let mut files_unpacked = 0; for file in archive.entries()? { let mut file = file?; - let file_path = output_folder.join(file.path()?); file.unpack_in(output_folder)?; // This is printed for every file in the archive and has little @@ -45,7 +44,7 @@ pub fn unpack_archive(reader: Box, output_folder: &Path, quiet: bool) file.size().bytes(), ); - files_unpacked.push(file_path); + files_unpacked += 1; } } diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 69dabb8..05af45d 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -29,13 +29,13 @@ use crate::{ /// Unpacks the archive given by `archive` into the folder given by `output_folder`. /// Assumes that output_folder is empty -pub fn unpack_archive(mut archive: ZipArchive, output_folder: &Path, quiet: bool) -> crate::Result> +pub fn unpack_archive(mut archive: ZipArchive, output_folder: &Path, quiet: bool) -> crate::Result where R: Read + Seek, { assert!(output_folder.read_dir().expect("dir exists").count() == 0); - let mut unpacked_files = Vec::with_capacity(archive.len()); + let mut unpacked_files = 0; for idx in 0..archive.len() { let mut file = archive.by_index(idx)?; @@ -87,7 +87,7 @@ where #[cfg(unix)] unix_set_permissions(&file_path, &file)?; - unpacked_files.push(file_path); + unpacked_files += 1; } Ok(unpacked_files) diff --git a/src/commands/decompress.rs b/src/commands/decompress.rs index d7a0167..03b2992 100644 --- a/src/commands/decompress.rs +++ b/src/commands/decompress.rs @@ -48,7 +48,7 @@ pub fn decompress_file( }] = formats.as_slice() { let zip_archive = zip::ZipArchive::new(reader)?; - let files = if let ControlFlow::Continue(files) = smart_unpack( + let files_unpacked = if let ControlFlow::Continue(files) = smart_unpack( |output_dir| crate::archive::zip::unpack_archive(zip_archive, output_dir, quiet), output_dir, &output_file_path, @@ -67,7 +67,7 @@ pub fn decompress_file( accessible, "Successfully decompressed archive in {} ({} files).", nice_directory_display(output_dir), - files.len() + files_unpacked ); return Ok(()); @@ -108,7 +108,7 @@ pub fn decompress_file( io::copy(&mut reader, &mut writer)?; - vec![output_file_path] + 1 } Tar => { if let ControlFlow::Continue(files) = smart_unpack( @@ -157,7 +157,7 @@ pub fn decompress_file( "Successfully decompressed archive in {}.", nice_directory_display(output_dir) ); - info!(accessible, "Files unpacked: {}", files_unpacked.len()); + info!(accessible, "Files unpacked: {}", files_unpacked); Ok(()) } @@ -168,11 +168,11 @@ pub fn decompress_file( /// output_dir named after the archive (given by `output_file_path`) /// Note: This functions assumes that `output_dir` exists fn smart_unpack( - unpack_fn: impl FnOnce(&Path) -> crate::Result>, + unpack_fn: impl FnOnce(&Path) -> crate::Result, output_dir: &Path, output_file_path: &Path, question_policy: QuestionPolicy, -) -> crate::Result>> { +) -> crate::Result> { assert!(output_dir.exists()); let temp_dir = tempfile::tempdir_in(output_dir)?; let temp_dir_path = temp_dir.path();