diff --git a/src/commands/compress.rs b/src/commands/compress.rs index 0f141bc..05166a7 100644 --- a/src/commands/compress.rs +++ b/src/commands/compress.rs @@ -7,7 +7,7 @@ use fs_err as fs; use crate::{ archive, - commands::warn_user_about_in_memory_zip_compression, + commands::warn_user_about_loading_zip_in_memory, extension::{ split_first_compression_format, CompressionFormat::{self, *}, @@ -114,7 +114,7 @@ pub fn compress_files( } Zip => { if formats.len() > 1 { - warn_user_about_in_memory_zip_compression(); + warn_user_about_loading_zip_in_memory(); // give user the option to continue compressing after warning is shown if !user_wants_to_continue(output_dir, question_policy, QuestionAction::Compression)? { diff --git a/src/commands/decompress.rs b/src/commands/decompress.rs index 7ddbc9c..21bae91 100644 --- a/src/commands/decompress.rs +++ b/src/commands/decompress.rs @@ -7,7 +7,7 @@ use std::{ use fs_err as fs; use crate::{ - commands::warn_user_about_in_memory_zip_decompression, + commands::warn_user_about_loading_zip_in_memory, extension::{ split_first_compression_format, CompressionFormat::{self, *}, @@ -152,7 +152,7 @@ pub fn decompress_file( } Zip => { if formats.len() > 1 { - warn_user_about_in_memory_zip_decompression(); + warn_user_about_loading_zip_in_memory(); // give user the option to continue decompressing after warning is shown if !user_wants_to_continue(input_file_path, question_policy, QuestionAction::Decompression)? { @@ -233,7 +233,7 @@ fn smart_unpack( .file_name() .expect("Should be safe because paths in archives should not end with '..'"); let correct_path = output_dir.join(file_name); - // One case to handle tough is we need to check if a file with the same name already exists + // Before moving, need to check if a file with the same name already exists if !utils::clear_path(&correct_path, question_policy)? { return Ok(ControlFlow::Break(())); } @@ -246,7 +246,7 @@ fn smart_unpack( ); } else { // Multiple files in the root directory, so: - // Rename the temporary directory to the archive name, which is output_file_path + // Rename the temporary directory to the archive name, which is output_file_path // One case to handle tough is we need to check if a file with the same name already exists if !utils::clear_path(output_file_path, question_policy)? { return Ok(ControlFlow::Break(())); diff --git a/src/commands/list.rs b/src/commands/list.rs index 6e27eb4..a5832d5 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -6,7 +6,7 @@ use std::{ use fs_err as fs; use crate::{ - commands::warn_user_about_in_memory_zip_decompression, + commands::warn_user_about_loading_zip_in_memory, extension::CompressionFormat::{self, *}, list::{self, FileInArchive, ListOptions}, utils::user_wants_to_continue, @@ -30,7 +30,7 @@ pub fn list_archive_contents( // in-memory decompression/copying first. // // Any other Zip decompression done can take up the whole RAM and freeze ouch. - if let [Zip] = *formats.as_slice() { + if let &[Zip] = formats.as_slice() { let zip_archive = zip::ZipArchive::new(reader)?; let files = crate::archive::zip::list_archive(zip_archive); list::list_files(archive_path, files, list_options)?; @@ -65,7 +65,7 @@ pub fn list_archive_contents( Tar => Box::new(crate::archive::tar::list_archive(tar::Archive::new(reader))), Zip => { if formats.len() > 1 { - warn_user_about_in_memory_zip_decompression(); + warn_user_about_loading_zip_in_memory(); // give user the option to continue decompressing after warning is shown if !user_wants_to_continue(archive_path, question_policy, QuestionAction::Decompression)? { diff --git a/src/commands/mod.rs b/src/commands/mod.rs index fb4e4f8..5e29ffa 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -28,28 +28,12 @@ use crate::{ warning, Opts, QuestionAction, QuestionPolicy, Subcommand, }; -/// Warn the user that .zip archives have limitations that require it to compress everything -/// in-memory when working with multiple chained formats. -/// -/// This can sadly lead to out-of-memory scenarios for big archives. -fn warn_user_about_in_memory_zip_compression() { - const ZIP_IN_MEMORY_LIMITATION_WARNING: &str = - "\tThere is a limitation for .zip archives with extra extensions. (e.g. .zip.gz)\n\ - \tThe design of .zip makes it impossible to compress via stream, so it must be done entirely in memory.\n\ - \tBy compressing .zip with extra compression formats, you can run out of RAM if the file is too large!"; - - warning!("{}", ZIP_IN_MEMORY_LIMITATION_WARNING); -} - -/// Warn the user that .zip archives have limitations that require it to decompress everything -/// in-memory when working with multiple chained formats. -/// -/// This can sadly lead to out-of-memory scenarios for big archives. -fn warn_user_about_in_memory_zip_decompression() { - const ZIP_IN_MEMORY_LIMITATION_WARNING: &str = - "\tThere is a limitation for .zip archives with extra extensions. (e.g. .zip.gz)\n\ - \tThe design of .zip makes it impossible to compress via stream, so it must be done entirely in memory.\n\ - \tBy compressing .zip with extra compression formats, you can run out of RAM if the file is too large!"; +/// Warn the user that (de)compressing this .zip archive might freeze their system. +fn warn_user_about_loading_zip_in_memory() { + const ZIP_IN_MEMORY_LIMITATION_WARNING: &str = "\n\ + \tThe format '.zip' is limited and cannot be (de)compressed using encoding streams.\n\ + \tWhen using '.zip' with other formats, (de)compression must be done in-memory\n\ + \tCareful, you might run out of RAM if the archive is too large!"; warning!("{}", ZIP_IN_MEMORY_LIMITATION_WARNING); } diff --git a/src/macros.rs b/src/macros.rs index dfe6b62..c2d209b 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -69,8 +69,8 @@ pub fn _warning_helper() { use crate::utils::colors::{ORANGE, RESET}; if *crate::cli::ACCESSIBLE.get().unwrap() { - print!("{}Warning:{} ", *ORANGE, *RESET); + eprint!("{}Warning:{} ", *ORANGE, *RESET); } else { - print!("{}[WARNING]{} ", *ORANGE, *RESET); + eprint!("{}[WARNING]{} ", *ORANGE, *RESET); } } diff --git a/src/utils/question.rs b/src/utils/question.rs index a15c660..bea92dd 100644 --- a/src/utils/question.rs +++ b/src/utils/question.rs @@ -83,13 +83,13 @@ pub fn user_wants_to_continue( QuestionPolicy::AlwaysNo => Ok(false), QuestionPolicy::Ask => { let action = match question_action { - QuestionAction::Compression => "compressing", - QuestionAction::Decompression => "decompressing", + QuestionAction::Compression => "compress", + QuestionAction::Decompression => "decompress", }; let path = to_utf(strip_cur_dir(path)); let path = Some(&*path); let placeholder = Some("FILE"); - Confirmation::new(&format!("Do you want to continue {} 'FILE'?", action), placeholder).ask(path) + Confirmation::new(&format!("Do you want to {} 'FILE'?", action), placeholder).ask(path) } } }