mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 20:15:27 +00:00
Stop keeping track of the names of unpacked files
This commit is contained in:
parent
60bbf438fc
commit
3bb0e57ed4
@ -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<dyn Read>, output_folder: &Path, quiet: bool) -> crate::Result<Vec<PathBuf>> {
|
||||
pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path, quiet: bool) -> crate::Result<usize> {
|
||||
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<dyn Read>, output_folder: &Path, quiet: bool)
|
||||
file.size().bytes(),
|
||||
);
|
||||
|
||||
files_unpacked.push(file_path);
|
||||
files_unpacked += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<R>(mut archive: ZipArchive<R>, output_folder: &Path, quiet: bool) -> crate::Result<Vec<PathBuf>>
|
||||
pub fn unpack_archive<R>(mut archive: ZipArchive<R>, output_folder: &Path, quiet: bool) -> crate::Result<usize>
|
||||
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)
|
||||
|
@ -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<Vec<PathBuf>>,
|
||||
unpack_fn: impl FnOnce(&Path) -> crate::Result<usize>,
|
||||
output_dir: &Path,
|
||||
output_file_path: &Path,
|
||||
question_policy: QuestionPolicy,
|
||||
) -> crate::Result<ControlFlow<(), Vec<PathBuf>>> {
|
||||
) -> crate::Result<ControlFlow<(), usize>> {
|
||||
assert!(output_dir.exists());
|
||||
let temp_dir = tempfile::tempdir_in(output_dir)?;
|
||||
let temp_dir_path = temp_dir.path();
|
||||
|
Loading…
x
Reference in New Issue
Block a user