mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 20:15:27 +00:00
move check_for_non_archive_formats
to check.rs
This commit is contained in:
parent
b938dc014c
commit
6710987b38
28
src/check.rs
28
src/check.rs
@ -1,9 +1,10 @@
|
|||||||
use std::{ops::ControlFlow, path::PathBuf};
|
use std::{ops::ControlFlow, path::PathBuf};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
error::FinalError,
|
||||||
extension::Extension,
|
extension::Extension,
|
||||||
info,
|
info,
|
||||||
utils::{try_infer_extension, user_wants_to_continue},
|
utils::{pretty_format_list_of_paths, try_infer_extension, user_wants_to_continue},
|
||||||
warning, QuestionAction, QuestionPolicy,
|
warning, QuestionAction, QuestionPolicy,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -56,3 +57,28 @@ pub fn check_mime_type(
|
|||||||
}
|
}
|
||||||
Ok(ControlFlow::Continue(()))
|
Ok(ControlFlow::Continue(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// In the context of listing archives, this function checks if `ouch` was told to list
|
||||||
|
/// the contents of a compressed file that is not an archive
|
||||||
|
pub fn check_for_non_archive_formats(files: &[PathBuf], formats: &[Vec<Extension>]) -> crate::Result<()> {
|
||||||
|
let mut not_archives = files
|
||||||
|
.iter()
|
||||||
|
.zip(formats)
|
||||||
|
.filter(|(_, formats)| !formats.first().map(Extension::is_archive).unwrap_or(false))
|
||||||
|
.map(|(path, _)| path)
|
||||||
|
.peekable();
|
||||||
|
|
||||||
|
if not_archives.peek().is_some() {
|
||||||
|
let not_archives: Vec<_> = not_archives.collect();
|
||||||
|
let error = FinalError::with_title("Cannot list archive contents")
|
||||||
|
.detail("Only archives can have their contents listed")
|
||||||
|
.detail(format!(
|
||||||
|
"Files are not archives: {}",
|
||||||
|
pretty_format_list_of_paths(¬_archives)
|
||||||
|
));
|
||||||
|
|
||||||
|
return Err(error.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
@ -10,11 +10,11 @@ use rayon::prelude::{IndexedParallelIterator, IntoParallelRefIterator, ParallelI
|
|||||||
use utils::colors;
|
use utils::colors;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
check::check_mime_type,
|
check::{check_for_non_archive_formats, check_mime_type},
|
||||||
cli::Subcommand,
|
cli::Subcommand,
|
||||||
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, build_archive_file_suggestion, parse_format, Extension},
|
extension::{self, build_archive_file_suggestion, parse_format},
|
||||||
info,
|
info,
|
||||||
list::ListOptions,
|
list::ListOptions,
|
||||||
utils::{self, pretty_format_list_of_paths, to_utf, EscapedPathDisplay, FileVisibilityPolicy},
|
utils::{self, pretty_format_list_of_paths, to_utf, EscapedPathDisplay, FileVisibilityPolicy},
|
||||||
@ -31,31 +31,6 @@ fn warn_user_about_loading_zip_in_memory() {
|
|||||||
warning!("{}", ZIP_IN_MEMORY_LIMITATION_WARNING);
|
warning!("{}", ZIP_IN_MEMORY_LIMITATION_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// In the context of listing archives, this function checks if `ouch` was told to list
|
|
||||||
/// the contents of a compressed file that is not an archive
|
|
||||||
fn check_for_non_archive_formats(files: &[PathBuf], formats: &[Vec<Extension>]) -> crate::Result<()> {
|
|
||||||
let mut not_archives = files
|
|
||||||
.iter()
|
|
||||||
.zip(formats)
|
|
||||||
.filter(|(_, formats)| !formats.first().map(Extension::is_archive).unwrap_or(false))
|
|
||||||
.map(|(path, _)| path)
|
|
||||||
.peekable();
|
|
||||||
|
|
||||||
if not_archives.peek().is_some() {
|
|
||||||
let not_archives: Vec<_> = not_archives.collect();
|
|
||||||
let error = FinalError::with_title("Cannot list archive contents")
|
|
||||||
.detail("Only archives can have their contents listed")
|
|
||||||
.detail(format!(
|
|
||||||
"Files are not archives: {}",
|
|
||||||
pretty_format_list_of_paths(¬_archives)
|
|
||||||
));
|
|
||||||
|
|
||||||
return Err(error.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This function checks what command needs to be run and performs A LOT of ahead-of-time checks
|
/// This function checks what command needs to be run and performs A LOT of ahead-of-time checks
|
||||||
/// to assume everything is OK.
|
/// to assume everything is OK.
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user