fix some errors + warnings

This commit is contained in:
Antonios Barotsis 2024-03-12 02:32:03 +01:00 committed by João Marcos
parent 380893b6df
commit b04122a6de
9 changed files with 14 additions and 16 deletions

View File

@ -17,7 +17,6 @@ use crate::{
message::{MessageLevel, PrintMessage}, message::{MessageLevel, PrintMessage},
Bytes, EscapedPathDisplay, FileVisibilityPolicy, Bytes, EscapedPathDisplay, FileVisibilityPolicy,
}, },
warning,
}; };
pub fn compress_sevenz<W>( pub fn compress_sevenz<W>(

View File

@ -19,7 +19,6 @@ use crate::{
message::{MessageLevel, PrintMessage}, message::{MessageLevel, PrintMessage},
Bytes, EscapedPathDisplay, FileVisibilityPolicy, Bytes, EscapedPathDisplay, FileVisibilityPolicy,
}, },
warning,
}; };
/// Unpacks the archive given by `archive` into the folder given by `into`. /// Unpacks the archive given by `archive` into the folder given by `into`.

View File

@ -24,7 +24,6 @@ use crate::{
message::{MessageLevel, PrintMessage}, message::{MessageLevel, PrintMessage},
pretty_format_list_of_paths, strip_cur_dir, Bytes, EscapedPathDisplay, FileVisibilityPolicy, pretty_format_list_of_paths, strip_cur_dir, Bytes, EscapedPathDisplay, FileVisibilityPolicy,
}, },
warning,
}; };
/// Unpacks the archive given by `archive` into the folder given by `output_folder`. /// Unpacks the archive given by `archive` into the folder given by `output_folder`.

View File

@ -16,7 +16,7 @@ use crate::{
message::{MessageLevel, PrintMessage}, message::{MessageLevel, PrintMessage},
pretty_format_list_of_paths, try_infer_extension, user_wants_to_continue, EscapedPathDisplay, pretty_format_list_of_paths, try_infer_extension, user_wants_to_continue, EscapedPathDisplay,
}, },
warning, QuestionAction, QuestionPolicy, Result, QuestionAction, QuestionPolicy, Result,
}; };
/// Check if the mime type matches the detected extensions. /// Check if the mime type matches the detected extensions.

View File

@ -113,7 +113,7 @@ pub fn compress_files(
} }
Zip => { Zip => {
if !formats.is_empty() { if !formats.is_empty() {
warn_user_about_loading_zip_in_memory(); warn_user_about_loading_zip_in_memory(log_sender.clone());
if !user_wants_to_continue(output_path, question_policy, QuestionAction::Compression)? { if !user_wants_to_continue(output_path, question_policy, QuestionAction::Compression)? {
return Ok(false); return Ok(false);
@ -142,7 +142,7 @@ pub fn compress_files(
} }
SevenZip => { SevenZip => {
if !formats.is_empty() { if !formats.is_empty() {
warn_user_about_loading_sevenz_in_memory(); warn_user_about_loading_sevenz_in_memory(log_sender.clone());
if !user_wants_to_continue(output_path, question_policy, QuestionAction::Compression)? { if !user_wants_to_continue(output_path, question_policy, QuestionAction::Compression)? {
return Ok(false); return Ok(false);

View File

@ -136,7 +136,7 @@ pub fn decompress_file(
} }
Zip => { Zip => {
if formats.len() > 1 { if formats.len() > 1 {
warn_user_about_loading_zip_in_memory(); warn_user_about_loading_zip_in_memory(log_sender.clone());
if !user_wants_to_continue(input_file_path, question_policy, QuestionAction::Decompression)? { if !user_wants_to_continue(input_file_path, question_policy, QuestionAction::Decompression)? {
return Ok(()); return Ok(());
@ -193,7 +193,7 @@ pub fn decompress_file(
} }
SevenZip => { SevenZip => {
if formats.len() > 1 { if formats.len() > 1 {
warn_user_about_loading_sevenz_in_memory(); warn_user_about_loading_sevenz_in_memory(log_sender.clone());
if !user_wants_to_continue(input_file_path, question_policy, QuestionAction::Decompression)? { if !user_wants_to_continue(input_file_path, question_policy, QuestionAction::Decompression)? {
return Ok(()); return Ok(());

View File

@ -1,6 +1,7 @@
use std::{ use std::{
io::{self, BufReader, Read}, io::{self, BufReader, Read},
path::Path, path::Path,
sync::mpsc::Sender,
}; };
use fs_err as fs; use fs_err as fs;
@ -9,7 +10,7 @@ use crate::{
commands::warn_user_about_loading_zip_in_memory, 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::{message::PrintMessage, user_wants_to_continue},
QuestionAction, QuestionPolicy, BUFFER_CAPACITY, QuestionAction, QuestionPolicy, BUFFER_CAPACITY,
}; };
@ -20,6 +21,7 @@ pub fn list_archive_contents(
formats: Vec<CompressionFormat>, formats: Vec<CompressionFormat>,
list_options: ListOptions, list_options: ListOptions,
question_policy: QuestionPolicy, question_policy: QuestionPolicy,
log_sender: Sender<PrintMessage>,
) -> crate::Result<()> { ) -> crate::Result<()> {
let reader = fs::File::open(archive_path)?; let reader = fs::File::open(archive_path)?;
@ -65,7 +67,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_loading_zip_in_memory(); warn_user_about_loading_zip_in_memory(log_sender.clone());
if !user_wants_to_continue(archive_path, question_policy, QuestionAction::Decompression)? { if !user_wants_to_continue(archive_path, question_policy, QuestionAction::Decompression)? {
return Ok(()); return Ok(());
@ -94,7 +96,7 @@ pub fn list_archive_contents(
} }
SevenZip => { SevenZip => {
if formats.len() > 1 { if formats.len() > 1 {
warn_user_about_loading_zip_in_memory(); warn_user_about_loading_zip_in_memory(log_sender.clone());
if !user_wants_to_continue(archive_path, question_policy, QuestionAction::Decompression)? { if !user_wants_to_continue(archive_path, question_policy, QuestionAction::Decompression)? {
return Ok(()); return Ok(());
} }

View File

@ -29,7 +29,7 @@ use crate::{
message::{MessageLevel, PrintMessage}, message::{MessageLevel, PrintMessage},
to_utf, EscapedPathDisplay, FileVisibilityPolicy, to_utf, EscapedPathDisplay, FileVisibilityPolicy,
}, },
warning, CliArgs, QuestionPolicy, CliArgs, QuestionPolicy,
}; };
/// Warn the user that (de)compressing this .zip archive might freeze their system. /// Warn the user that (de)compressing this .zip archive might freeze their system.
@ -41,7 +41,7 @@ fn warn_user_about_loading_zip_in_memory(log_sender: Sender<PrintMessage>) {
log_sender log_sender
.send(PrintMessage { .send(PrintMessage {
contents: format!("{}", ZIP_IN_MEMORY_LIMITATION_WARNING), contents: ZIP_IN_MEMORY_LIMITATION_WARNING.to_string(),
accessible: true, accessible: true,
level: MessageLevel::Warning, level: MessageLevel::Warning,
}) })
@ -57,7 +57,7 @@ fn warn_user_about_loading_sevenz_in_memory(log_sender: Sender<PrintMessage>) {
log_sender log_sender
.send(PrintMessage { .send(PrintMessage {
contents: format!("{}", SEVENZ_IN_MEMORY_LIMITATION_WARNING), contents: SEVENZ_IN_MEMORY_LIMITATION_WARNING.to_string(),
accessible: true, accessible: true,
level: MessageLevel::Warning, level: MessageLevel::Warning,
}) })
@ -323,7 +323,7 @@ pub fn run(
println!(); println!();
} }
let formats = extension::flatten_compression_formats(&formats); let formats = extension::flatten_compression_formats(&formats);
list_archive_contents(archive_path, formats, list_options, question_policy)?; list_archive_contents(archive_path, formats, list_options, question_policy, log_sender.clone())?;
} }
} }
} }

View File

@ -8,7 +8,6 @@ use self::CompressionFormat::*;
use crate::{ use crate::{
error::Error, error::Error,
utils::message::{MessageLevel, PrintMessage}, utils::message::{MessageLevel, PrintMessage},
warning,
}; };
pub const SUPPORTED_EXTENSIONS: &[&str] = &[ pub const SUPPORTED_EXTENSIONS: &[&str] = &[