style: cargo fmt

This commit is contained in:
ttyS3 2024-09-06 15:55:51 +00:00 committed by João Marcos
parent 84f1ec4daf
commit f8f1439ec5
4 changed files with 30 additions and 24 deletions

View File

@ -55,14 +55,17 @@ pub fn list_archive(
}; };
let result = match archive.open_for_listing() { let result = match archive.open_for_listing() {
Ok(iter) => iter.map(|item| { Ok(iter) => iter
let item = item?; .map(|item| {
let is_dir = item.is_directory(); let item = item?;
let path = item.filename; let is_dir = item.is_directory();
let path = item.filename;
Ok(FileInArchive { path, is_dir }) Ok(FileInArchive { path, is_dir })
}).collect::<Vec<_>>().into_iter(), })
Err(e) => return Err(Error::UnrarError{reason: e.to_string()}), .collect::<Vec<_>>()
.into_iter(),
Err(e) => return Err(Error::UnrarError { reason: e.to_string() }),
}; };
Ok(result) Ok(result)

View File

@ -12,7 +12,7 @@ use same_file::Handle;
use sevenz_rust::SevenZArchiveEntry; use sevenz_rust::SevenZArchiveEntry;
use crate::{ use crate::{
error::FinalError, error::{Error, FinalError},
list::FileInArchive, list::FileInArchive,
utils::{ utils::{
self, cd_into_same_dir_as, self, cd_into_same_dir_as,
@ -20,7 +20,6 @@ use crate::{
Bytes, EscapedPathDisplay, FileVisibilityPolicy, Bytes, EscapedPathDisplay, FileVisibilityPolicy,
}, },
}; };
use crate::error::Error;
pub fn compress_sevenz<W>( pub fn compress_sevenz<W>(
files: &[PathBuf], files: &[PathBuf],
@ -100,12 +99,7 @@ where
Ok(bytes) Ok(bytes)
} }
pub fn decompress_sevenz<R>( pub fn decompress_sevenz<R>(reader: R, output_path: &Path, password: Option<&[u8]>, quiet: bool) -> crate::Result<usize>
reader: R,
output_path: &Path,
password: Option<&[u8]>,
quiet: bool,
) -> crate::Result<usize>
where where
R: Read + Seek, R: Read + Seek,
{ {
@ -166,8 +160,8 @@ where
Some(password) => sevenz_rust::decompress_with_extract_fn_and_password( Some(password) => sevenz_rust::decompress_with_extract_fn_and_password(
reader, reader,
output_path, output_path,
sevenz_rust::Password::from(password.to_str().map_err(|_| { sevenz_rust::Password::from(password.to_str().map_err(|_| Error::InvalidPassword {
Error::InvalidPassword{reason: "7z requires that all passwords are valid UTF-8".to_string()} reason: "7z requires that all passwords are valid UTF-8".to_string(),
})?), })?),
entry_extract_fn, entry_extract_fn,
)?, )?,
@ -198,7 +192,11 @@ pub fn list_archive(
Some(password) => { Some(password) => {
let password = match password.to_str() { let password = match password.to_str() {
Ok(p) => p, Ok(p) => p,
Err(err) => return Err(Error::InvalidPassword{ reason: err.to_string()}), Err(err) => {
return Err(Error::InvalidPassword {
reason: err.to_string(),
})
}
}; };
sevenz_rust::decompress_with_extract_fn_and_password( sevenz_rust::decompress_with_extract_fn_and_password(
reader, reader,
@ -206,7 +204,7 @@ pub fn list_archive(
sevenz_rust::Password::from(password), sevenz_rust::Password::from(password),
entry_extract_fn, entry_extract_fn,
) )
}, }
None => sevenz_rust::decompress_with_extract_fn(reader, ".", entry_extract_fn), None => sevenz_rust::decompress_with_extract_fn(reader, ".", entry_extract_fn),
}; };

View File

@ -5,9 +5,10 @@ mod decompress;
mod list; mod list;
use std::{ops::ControlFlow, path::PathBuf}; use std::{ops::ControlFlow, path::PathBuf};
use bstr::ByteSlice;
use rayon::prelude::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; use rayon::prelude::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
use utils::colors; use utils::colors;
use bstr::ByteSlice;
use crate::{ use crate::{
check, check,
@ -188,7 +189,9 @@ pub fn run(
output_file_path, output_file_path,
question_policy, question_policy,
args.quiet, args.quiet,
args.password.as_deref().map(|str| <[u8] as ByteSlice>::from_os_str(str).expect("convert password to bytes failed")), args.password.as_deref().map(|str| {
<[u8] as ByteSlice>::from_os_str(str).expect("convert password to bytes failed")
}),
) )
}) })
} }
@ -227,7 +230,9 @@ pub fn run(
formats, formats,
list_options, list_options,
question_policy, question_policy,
args.password.as_deref().map(|str| <[u8] as ByteSlice>::from_os_str(str).expect("convert password to bytes failed")), args.password
.as_deref()
.map(|str| <[u8] as ByteSlice>::from_os_str(str).expect("convert password to bytes failed")),
)?; )?;
} }

View File

@ -152,8 +152,8 @@ impl fmt::Display for Error {
Error::UnsupportedFormat { reason } => { Error::UnsupportedFormat { reason } => {
FinalError::with_title("Recognised but unsupported format").detail(reason.clone()) FinalError::with_title("Recognised but unsupported format").detail(reason.clone())
} }
Error::InvalidPassword{reason} => FinalError::with_title("Invalid password").detail(reason.clone()), Error::InvalidPassword { reason } => FinalError::with_title("Invalid password").detail(reason.clone()),
Error::UnrarError{reason} => FinalError::with_title("Unrar error").detail(reason.clone()), Error::UnrarError { reason } => FinalError::with_title("Unrar error").detail(reason.clone()),
}; };
write!(f, "{err}") write!(f, "{err}")