From 69b1db4a35a538791024ccb891776513f0b05c48 Mon Sep 17 00:00:00 2001 From: Flat Date: Sat, 25 Nov 2023 14:55:57 -0500 Subject: [PATCH] chore: cargo fmt --- src/archive/sevenz.rs | 36 ++++++++++++++++++++++-------------- src/commands/compress.rs | 8 +++----- src/commands/decompress.rs | 6 +++--- src/commands/list.rs | 4 ++-- src/extension.rs | 4 +++- src/main.rs | 3 ++- tests/ui.rs | 1 - 7 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/archive/sevenz.rs b/src/archive/sevenz.rs index 7269d16..d88c0b2 100644 --- a/src/archive/sevenz.rs +++ b/src/archive/sevenz.rs @@ -2,14 +2,15 @@ use std::{ env, fs::File, - path::{Path, PathBuf}, io::{Write, Seek, Read}, + io::{Read, Seek, Write}, + path::{Path, PathBuf}, }; use same_file::Handle; use crate::{ info, - utils::{self, cd_into_same_dir_as, EscapedPathDisplay, FileVisibilityPolicy, Bytes}, + utils::{self, cd_into_same_dir_as, Bytes, EscapedPathDisplay, FileVisibilityPolicy}, warning, }; @@ -21,8 +22,8 @@ pub fn compress_sevenz( quiet: bool, ) -> crate::Result where -W: Write + Seek { - + W: Write + Seek, +{ let mut writer = sevenz_rust::SevenZWriter::new(writer).map_err(crate::Error::SevenzipError)?; let output_handle = Handle::from_path(output_path); for filename in files { @@ -91,8 +92,10 @@ W: Write + Seek { Ok(bytes) } -pub fn decompress_sevenz(reader: R, output_path: &Path, quiet: bool) -> crate::Result -where R: Read+ Seek { +pub fn decompress_sevenz(reader: R, output_path: &Path, quiet: bool) -> crate::Result +where + R: Read + Seek, +{ let mut count: usize = 0; sevenz_rust::decompress_with_extract_fn(reader, output_path, |entry, reader, dest| { count += 1; @@ -102,15 +105,20 @@ where R: Read+ Seek { use filetime_creation as ft; let file_path = output_path.join(entry.name()); - + if entry.is_directory() { - // This is printed for every file in the archive and has little - // importance for most users, but would generate lots of - // spoken text for users using screen readers, braille displays - // and so on - if !quiet { - info!(inaccessible, "File {} extracted to \"{}\"", entry.name(), file_path.display()); - } + // This is printed for every file in the archive and has little + // importance for most users, but would generate lots of + // spoken text for users using screen readers, braille displays + // and so on + if !quiet { + info!( + inaccessible, + "File {} extracted to \"{}\"", + entry.name(), + file_path.display() + ); + } let dir = dest; if !dir.exists() { std::fs::create_dir_all(dir)?; diff --git a/src/commands/compress.rs b/src/commands/compress.rs index c73191d..5150fff 100644 --- a/src/commands/compress.rs +++ b/src/commands/compress.rs @@ -5,6 +5,7 @@ use std::{ use fs_err as fs; +use super::warn_user_about_loading_sevenz_in_memory; use crate::{ archive, commands::warn_user_about_loading_zip_in_memory, @@ -13,8 +14,6 @@ use crate::{ QuestionAction, QuestionPolicy, BUFFER_CAPACITY, }; -use super::warn_user_about_loading_sevenz_in_memory; - /// Compress files into `output_file`. /// /// # Arguments: @@ -123,13 +122,12 @@ pub fn compress_files( )?; vec_buffer.rewind()?; io::copy(&mut vec_buffer, &mut writer)?; - }, + } Rar => { archive::rar::no_compression_notice(); return Ok(false); - }, + } SevenZip => { - if !formats.is_empty() { warn_user_about_loading_sevenz_in_memory(); diff --git a/src/commands/decompress.rs b/src/commands/decompress.rs index b7cd0b3..c717dbc 100644 --- a/src/commands/decompress.rs +++ b/src/commands/decompress.rs @@ -7,7 +7,7 @@ use std::{ use fs_err as fs; use crate::{ - commands::{warn_user_about_loading_zip_in_memory, warn_user_about_loading_sevenz_in_memory}, + commands::{warn_user_about_loading_sevenz_in_memory, warn_user_about_loading_zip_in_memory}, extension::{ split_first_compression_format, CompressionFormat::{self, *}, @@ -145,7 +145,7 @@ pub fn decompress_file( } else { return Ok(()); } - }, + } Rar => { type UnpackResult = crate::Result; let unpack_fn: Box UnpackResult> = if formats.len() > 1 { @@ -163,7 +163,7 @@ pub fn decompress_file( } else { return Ok(()); } - }, + } SevenZip => { if formats.len() > 1 { warn_user_about_loading_sevenz_in_memory(); diff --git a/src/commands/list.rs b/src/commands/list.rs index 0fdaa52..092ea3c 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -77,7 +77,7 @@ pub fn list_archive_contents( let zip_archive = zip::ZipArchive::new(io::Cursor::new(vec))?; Box::new(crate::archive::zip::list_archive(zip_archive)) - }, + } Rar => { if formats.len() > 1 { let mut temp_file = tempfile::NamedTempFile::new()?; @@ -86,7 +86,7 @@ pub fn list_archive_contents( } else { Box::new(crate::archive::rar::list_archive(archive_path)) } - }, + } SevenZip => { if formats.len() > 1 { warn_user_about_loading_zip_in_memory(); diff --git a/src/extension.rs b/src/extension.rs index b31f501..b4029a8 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -7,7 +7,9 @@ use bstr::ByteSlice; use self::CompressionFormat::*; use crate::{error::Error, warning}; -pub const SUPPORTED_EXTENSIONS: &[&str] = &["tar", "zip", "bz", "bz2", "gz", "lz4", "xz", "lzma", "sz", "zst", "rar", "7z"]; +pub const SUPPORTED_EXTENSIONS: &[&str] = &[ + "tar", "zip", "bz", "bz2", "gz", "lz4", "xz", "lzma", "sz", "zst", "rar", "7z", +]; pub const SUPPORTED_ALIASES: &[&str] = &["tgz", "tbz", "tlz4", "txz", "tzlma", "tsz", "tzst"]; pub const PRETTY_SUPPORTED_EXTENSIONS: &str = "tar, zip, bz, bz2, gz, lz4, xz, lzma, sz, zst, rar"; pub const PRETTY_SUPPORTED_ALIASES: &str = "tgz, tbz, tlz4, txz, tzlma, tsz, tzst"; diff --git a/src/main.rs b/src/main.rs index 060177d..9a161e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,8 @@ use utils::{QuestionAction, QuestionPolicy}; const BUFFER_CAPACITY: usize = 1024 * 32; /// Current directory or empty directory -static CURRENT_DIRECTORY: Lazy = Lazy::new(|| std::fs::canonicalize(env::current_dir().unwrap_or_default()).unwrap_or_default()); +static CURRENT_DIRECTORY: Lazy = + Lazy::new(|| std::fs::canonicalize(env::current_dir().unwrap_or_default()).unwrap_or_default()); /// The status code returned from `ouch` on error pub const EXIT_FAILURE: i32 = libc::EXIT_FAILURE; diff --git a/tests/ui.rs b/tests/ui.rs index eee6e33..513dce7 100644 --- a/tests/ui.rs +++ b/tests/ui.rs @@ -83,7 +83,6 @@ fn ui_test_err_decompress_missing_extension() { #[cfg(windows)] run_in(dir, "cmd", "/C copy nul b.unknown").unwrap(); - ui!(run_ouch("ouch decompress a", dir)); ui!(run_ouch("ouch decompress a b.unknown", dir));