mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 19:45:29 +00:00
small changes and rewrite zip warning message
This commit is contained in:
parent
97c4387fcf
commit
278bc980c1
@ -7,7 +7,7 @@ use fs_err as fs;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
archive,
|
archive,
|
||||||
commands::warn_user_about_in_memory_zip_compression,
|
commands::warn_user_about_loading_zip_in_memory,
|
||||||
extension::{
|
extension::{
|
||||||
split_first_compression_format,
|
split_first_compression_format,
|
||||||
CompressionFormat::{self, *},
|
CompressionFormat::{self, *},
|
||||||
@ -114,7 +114,7 @@ pub fn compress_files(
|
|||||||
}
|
}
|
||||||
Zip => {
|
Zip => {
|
||||||
if formats.len() > 1 {
|
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
|
// give user the option to continue compressing after warning is shown
|
||||||
if !user_wants_to_continue(output_dir, question_policy, QuestionAction::Compression)? {
|
if !user_wants_to_continue(output_dir, question_policy, QuestionAction::Compression)? {
|
||||||
|
@ -7,7 +7,7 @@ use std::{
|
|||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
commands::warn_user_about_in_memory_zip_decompression,
|
commands::warn_user_about_loading_zip_in_memory,
|
||||||
extension::{
|
extension::{
|
||||||
split_first_compression_format,
|
split_first_compression_format,
|
||||||
CompressionFormat::{self, *},
|
CompressionFormat::{self, *},
|
||||||
@ -152,7 +152,7 @@ pub fn decompress_file(
|
|||||||
}
|
}
|
||||||
Zip => {
|
Zip => {
|
||||||
if formats.len() > 1 {
|
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
|
// give user the option to continue decompressing after warning is shown
|
||||||
if !user_wants_to_continue(input_file_path, question_policy, QuestionAction::Decompression)? {
|
if !user_wants_to_continue(input_file_path, question_policy, QuestionAction::Decompression)? {
|
||||||
@ -233,7 +233,7 @@ fn smart_unpack(
|
|||||||
.file_name()
|
.file_name()
|
||||||
.expect("Should be safe because paths in archives should not end with '..'");
|
.expect("Should be safe because paths in archives should not end with '..'");
|
||||||
let correct_path = output_dir.join(file_name);
|
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)? {
|
if !utils::clear_path(&correct_path, question_policy)? {
|
||||||
return Ok(ControlFlow::Break(()));
|
return Ok(ControlFlow::Break(()));
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ fn smart_unpack(
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Multiple files in the root directory, so:
|
// 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
|
// 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)? {
|
if !utils::clear_path(output_file_path, question_policy)? {
|
||||||
return Ok(ControlFlow::Break(()));
|
return Ok(ControlFlow::Break(()));
|
||||||
|
@ -6,7 +6,7 @@ use std::{
|
|||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
commands::warn_user_about_in_memory_zip_decompression,
|
commands::warn_user_about_loading_zip_in_memory,
|
||||||
extension::CompressionFormat::{self, *},
|
extension::CompressionFormat::{self, *},
|
||||||
list::{self, FileInArchive, ListOptions},
|
list::{self, FileInArchive, ListOptions},
|
||||||
utils::user_wants_to_continue,
|
utils::user_wants_to_continue,
|
||||||
@ -30,7 +30,7 @@ pub fn list_archive_contents(
|
|||||||
// in-memory decompression/copying first.
|
// in-memory decompression/copying first.
|
||||||
//
|
//
|
||||||
// Any other Zip decompression done can take up the whole RAM and freeze ouch.
|
// 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 zip_archive = zip::ZipArchive::new(reader)?;
|
||||||
let files = crate::archive::zip::list_archive(zip_archive);
|
let files = crate::archive::zip::list_archive(zip_archive);
|
||||||
list::list_files(archive_path, files, list_options)?;
|
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))),
|
Tar => Box::new(crate::archive::tar::list_archive(tar::Archive::new(reader))),
|
||||||
Zip => {
|
Zip => {
|
||||||
if formats.len() > 1 {
|
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
|
// give user the option to continue decompressing after warning is shown
|
||||||
if !user_wants_to_continue(archive_path, question_policy, QuestionAction::Decompression)? {
|
if !user_wants_to_continue(archive_path, question_policy, QuestionAction::Decompression)? {
|
||||||
|
@ -28,28 +28,12 @@ use crate::{
|
|||||||
warning, Opts, QuestionAction, QuestionPolicy, Subcommand,
|
warning, Opts, QuestionAction, QuestionPolicy, Subcommand,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Warn the user that .zip archives have limitations that require it to compress everything
|
/// Warn the user that (de)compressing this .zip archive might freeze their system.
|
||||||
/// in-memory when working with multiple chained formats.
|
fn warn_user_about_loading_zip_in_memory() {
|
||||||
///
|
const ZIP_IN_MEMORY_LIMITATION_WARNING: &str = "\n\
|
||||||
/// This can sadly lead to out-of-memory scenarios for big archives.
|
\tThe format '.zip' is limited and cannot be (de)compressed using encoding streams.\n\
|
||||||
fn warn_user_about_in_memory_zip_compression() {
|
\tWhen using '.zip' with other formats, (de)compression must be done in-memory\n\
|
||||||
const ZIP_IN_MEMORY_LIMITATION_WARNING: &str =
|
\tCareful, you might run out of RAM if the archive is too large!";
|
||||||
"\tThere is a limitation for .zip archives with extra extensions. (e.g. <file>.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. <file>.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);
|
warning!("{}", ZIP_IN_MEMORY_LIMITATION_WARNING);
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,8 @@ pub fn _warning_helper() {
|
|||||||
use crate::utils::colors::{ORANGE, RESET};
|
use crate::utils::colors::{ORANGE, RESET};
|
||||||
|
|
||||||
if *crate::cli::ACCESSIBLE.get().unwrap() {
|
if *crate::cli::ACCESSIBLE.get().unwrap() {
|
||||||
print!("{}Warning:{} ", *ORANGE, *RESET);
|
eprint!("{}Warning:{} ", *ORANGE, *RESET);
|
||||||
} else {
|
} else {
|
||||||
print!("{}[WARNING]{} ", *ORANGE, *RESET);
|
eprint!("{}[WARNING]{} ", *ORANGE, *RESET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,13 +83,13 @@ pub fn user_wants_to_continue(
|
|||||||
QuestionPolicy::AlwaysNo => Ok(false),
|
QuestionPolicy::AlwaysNo => Ok(false),
|
||||||
QuestionPolicy::Ask => {
|
QuestionPolicy::Ask => {
|
||||||
let action = match question_action {
|
let action = match question_action {
|
||||||
QuestionAction::Compression => "compressing",
|
QuestionAction::Compression => "compress",
|
||||||
QuestionAction::Decompression => "decompressing",
|
QuestionAction::Decompression => "decompress",
|
||||||
};
|
};
|
||||||
let path = to_utf(strip_cur_dir(path));
|
let path = to_utf(strip_cur_dir(path));
|
||||||
let path = Some(&*path);
|
let path = Some(&*path);
|
||||||
let placeholder = Some("FILE");
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user