This commit is contained in:
Antonios Barotsis 2024-03-11 21:24:45 +01:00 committed by João Marcos
parent e2ac5c4c9b
commit 93752d5fb5
4 changed files with 25 additions and 21 deletions

View File

@ -20,7 +20,8 @@ use crate::{
error::FinalError, error::FinalError,
list::FileInArchive, list::FileInArchive,
utils::{ utils::{
self, cd_into_same_dir_as, get_invalid_utf8_paths, message::PrintMessage, pretty_format_list_of_paths, strip_cur_dir, Bytes, EscapedPathDisplay, FileVisibilityPolicy self, cd_into_same_dir_as, get_invalid_utf8_paths, message::PrintMessage, pretty_format_list_of_paths,
strip_cur_dir, Bytes, EscapedPathDisplay, FileVisibilityPolicy,
}, },
warning, warning,
}; };
@ -145,7 +146,7 @@ pub fn build_archive_from_paths<W>(
writer: W, writer: W,
file_visibility_policy: FileVisibilityPolicy, file_visibility_policy: FileVisibilityPolicy,
quiet: bool, quiet: bool,
log_sender: Sender<PrintMessage> log_sender: Sender<PrintMessage>,
) -> crate::Result<W> ) -> crate::Result<W>
where where
W: Write + Seek, W: Write + Seek,
@ -202,12 +203,10 @@ where
if !quiet { if !quiet {
log_sender log_sender
.send(PrintMessage { .send(PrintMessage {
contents: format!( contents: format!("Compressing '{}'.", EscapedPathDisplay::new(path)),
"Compressing '{}'.",
EscapedPathDisplay::new(path)
),
accessible: false, accessible: false,
}).unwrap(); })
.unwrap();
} }
let metadata = match path.metadata() { let metadata = match path.metadata() {

View File

@ -5,13 +5,17 @@
use std::{ use std::{
ffi::OsString, ffi::OsString,
ops::ControlFlow, ops::ControlFlow,
path::{Path, PathBuf}, sync::mpsc::Sender, path::{Path, PathBuf},
sync::mpsc::Sender,
}; };
use crate::{ use crate::{
error::FinalError, error::FinalError,
extension::{build_archive_file_suggestion, Extension, PRETTY_SUPPORTED_ALIASES, PRETTY_SUPPORTED_EXTENSIONS}, extension::{build_archive_file_suggestion, Extension, PRETTY_SUPPORTED_ALIASES, PRETTY_SUPPORTED_EXTENSIONS},
utils::{message::PrintMessage, pretty_format_list_of_paths, try_infer_extension, user_wants_to_continue, EscapedPathDisplay}, utils::{
message::PrintMessage, pretty_format_list_of_paths, try_infer_extension, user_wants_to_continue,
EscapedPathDisplay,
},
warning, QuestionAction, QuestionPolicy, Result, warning, QuestionAction, QuestionPolicy, Result,
}; };
@ -25,7 +29,7 @@ pub fn check_mime_type(
path: &Path, path: &Path,
formats: &mut Vec<Extension>, formats: &mut Vec<Extension>,
question_policy: QuestionPolicy, question_policy: QuestionPolicy,
log_sender: Sender<PrintMessage> log_sender: Sender<PrintMessage>,
) -> Result<ControlFlow<()>> { ) -> Result<ControlFlow<()>> {
if formats.is_empty() { if formats.is_empty() {
// File with no extension // File with no extension
@ -35,13 +39,10 @@ pub fn check_mime_type(
// mistyped, ...) which we should always inform the user about. // mistyped, ...) which we should always inform the user about.
log_sender log_sender
.send(PrintMessage { .send(PrintMessage {
contents: format!( contents: format!("Detected file: `{}` extension as `{}`", path.display(), detected_format),
"Detected file: `{}` extension as `{}`",
path.display(),
detected_format
),
accessible: true, accessible: true,
}).unwrap(); })
.unwrap();
if user_wants_to_continue(path, question_policy, QuestionAction::Decompression)? { if user_wants_to_continue(path, question_policy, QuestionAction::Decompression)? {
formats.push(detected_format); formats.push(detected_format);
} else { } else {
@ -76,7 +77,8 @@ pub fn check_mime_type(
path.display() path.display()
), ),
accessible: true, accessible: true,
}).unwrap(); })
.unwrap();
} }
Ok(ControlFlow::Continue(())) Ok(ControlFlow::Continue(()))
} }

View File

@ -128,7 +128,7 @@ pub fn compress_files(
&mut vec_buffer, &mut vec_buffer,
file_visibility_policy, file_visibility_policy,
quiet, quiet,
log_sender.clone() log_sender.clone(),
)?; )?;
vec_buffer.rewind()?; vec_buffer.rewind()?;
io::copy(&mut vec_buffer, &mut writer)?; io::copy(&mut vec_buffer, &mut writer)?;

View File

@ -19,7 +19,6 @@ use crate::{
commands::{compress::compress_files, decompress::decompress_file, list::list_archive_contents}, commands::{compress::compress_files, decompress::decompress_file, list::list_archive_contents},
error::{Error, FinalError}, error::{Error, FinalError},
extension::{self, parse_format}, extension::{self, parse_format},
info,
list::ListOptions, list::ListOptions,
utils::{self, message::PrintMessage, to_utf, EscapedPathDisplay, FileVisibilityPolicy}, utils::{self, message::PrintMessage, to_utf, EscapedPathDisplay, FileVisibilityPolicy},
warning, CliArgs, QuestionPolicy, warning, CliArgs, QuestionPolicy,
@ -198,7 +197,9 @@ pub fn run(
for path in files.iter() { for path in files.iter() {
let (pathbase, mut file_formats) = extension::separate_known_extensions_from_name(path); let (pathbase, mut file_formats) = extension::separate_known_extensions_from_name(path);
if let ControlFlow::Break(_) = check::check_mime_type(path, &mut file_formats, question_policy, log_sender.clone())? { if let ControlFlow::Break(_) =
check::check_mime_type(path, &mut file_formats, question_policy, log_sender.clone())?
{
return Ok(()); return Ok(());
} }
@ -247,7 +248,9 @@ pub fn run(
for path in files.iter() { for path in files.iter() {
let mut file_formats = extension::extensions_from_path(path); let mut file_formats = extension::extensions_from_path(path);
if let ControlFlow::Break(_) = check::check_mime_type(path, &mut file_formats, question_policy, log_sender.clone())? { if let ControlFlow::Break(_) =
check::check_mime_type(path, &mut file_formats, question_policy, log_sender.clone())?
{
return Ok(()); return Ok(());
} }