mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
Merge pull request #267 from figsoda/clippy
Apply clippy lints and simplify smart_unpack
This commit is contained in:
commit
e377dd3a3a
@ -140,6 +140,7 @@ Categories Used:
|
||||
- CI: Check the format with Github Action [\#126](https://github.com/ouch-org/ouch/pull/126) ([dcariotti](https://github.com/dcariotti))
|
||||
- CI: Rewrite [\#135](https://github.com/ouch-org/ouch/pull/135) ([figsoda](https://github.com/figsoda))
|
||||
- Improving error messages and removing dead error treatment code [\#140](https://github.com/ouch-org/ouch/pull/140) ([marcospb19](https://github.com/marcospb19))
|
||||
- Apply clippy lints and simplify smart_unpack [\#267](https://github.com/ouch-org/ouch/pull/267) ([figsoda](https://github.com/figsoda))
|
||||
|
||||
### Tweaks
|
||||
|
||||
|
@ -50,17 +50,8 @@ pub fn decompress_file(
|
||||
{
|
||||
let zip_archive = zip::ZipArchive::new(reader)?;
|
||||
let files = if let ControlFlow::Continue(files) = smart_unpack(
|
||||
Box::new(move |output_dir| {
|
||||
let mut progress = Progress::new_accessible_aware(total_input_size, true, None);
|
||||
crate::archive::zip::unpack_archive(
|
||||
zip_archive,
|
||||
output_dir,
|
||||
progress
|
||||
.as_mut()
|
||||
.map(Progress::display_handle)
|
||||
.unwrap_or(&mut io::stdout()),
|
||||
)
|
||||
}),
|
||||
|output_dir, progress| crate::archive::zip::unpack_archive(zip_archive, output_dir, progress),
|
||||
total_input_size,
|
||||
output_dir,
|
||||
&output_file_path,
|
||||
question_policy,
|
||||
@ -130,17 +121,8 @@ pub fn decompress_file(
|
||||
}
|
||||
Tar => {
|
||||
if let ControlFlow::Continue(files) = smart_unpack(
|
||||
Box::new(move |output_dir| {
|
||||
let mut progress = Progress::new_accessible_aware(total_input_size, true, None);
|
||||
crate::archive::tar::unpack_archive(
|
||||
reader,
|
||||
output_dir,
|
||||
progress
|
||||
.as_mut()
|
||||
.map(Progress::display_handle)
|
||||
.unwrap_or(&mut io::stdout()),
|
||||
)
|
||||
}),
|
||||
|output_dir, progress| crate::archive::tar::unpack_archive(reader, output_dir, progress),
|
||||
total_input_size,
|
||||
output_dir,
|
||||
&output_file_path,
|
||||
question_policy,
|
||||
@ -165,17 +147,8 @@ pub fn decompress_file(
|
||||
let zip_archive = zip::ZipArchive::new(io::Cursor::new(vec))?;
|
||||
|
||||
if let ControlFlow::Continue(files) = smart_unpack(
|
||||
Box::new(move |output_dir| {
|
||||
let mut progress = Progress::new_accessible_aware(total_input_size, true, None);
|
||||
crate::archive::zip::unpack_archive(
|
||||
zip_archive,
|
||||
output_dir,
|
||||
progress
|
||||
.as_mut()
|
||||
.map(Progress::display_handle)
|
||||
.unwrap_or(&mut io::stdout()),
|
||||
)
|
||||
}),
|
||||
|output_dir, progress| crate::archive::zip::unpack_archive(zip_archive, output_dir, progress),
|
||||
total_input_size,
|
||||
output_dir,
|
||||
&output_file_path,
|
||||
question_policy,
|
||||
@ -207,7 +180,8 @@ pub fn decompress_file(
|
||||
/// output_dir named after the archive (given by `output_file_path`)
|
||||
/// Note: This functions assumes that `output_dir` exists
|
||||
fn smart_unpack(
|
||||
unpack_fn: Box<dyn FnOnce(&Path) -> crate::Result<Vec<PathBuf>>>,
|
||||
unpack_fn: impl FnOnce(&Path, &mut dyn Write) -> crate::Result<Vec<PathBuf>>,
|
||||
total_input_size: u64,
|
||||
output_dir: &Path,
|
||||
output_file_path: &Path,
|
||||
question_policy: QuestionPolicy,
|
||||
@ -222,7 +196,13 @@ fn smart_unpack(
|
||||
);
|
||||
|
||||
// unpack the files
|
||||
let files = unpack_fn(temp_dir_path)?;
|
||||
let files = unpack_fn(
|
||||
temp_dir_path,
|
||||
Progress::new_accessible_aware(total_input_size, true, None)
|
||||
.as_mut()
|
||||
.map(Progress::display_handle)
|
||||
.unwrap_or(&mut io::stdout()),
|
||||
)?;
|
||||
|
||||
let root_contains_only_one_element = fs::read_dir(&temp_dir_path)?.count() == 1;
|
||||
if root_contains_only_one_element {
|
||||
|
@ -31,7 +31,7 @@ mod utf8 {
|
||||
pub fn get_invalid_utf8_paths(paths: &[PathBuf]) -> Vec<&PathBuf> {
|
||||
paths
|
||||
.iter()
|
||||
.filter_map(|path| is_invalid_utf8(path).then(|| path))
|
||||
.filter_map(|path| is_invalid_utf8(path).then_some(path))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user