mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-05 02:55:31 +00:00
chore: cargo fmt
This commit is contained in:
parent
633d1dedd0
commit
69b1db4a35
@ -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<W>(
|
||||
quiet: bool,
|
||||
) -> crate::Result<W>
|
||||
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<R>(reader: R, output_path: &Path, quiet: bool) -> crate::Result<usize>
|
||||
where R: Read+ Seek {
|
||||
pub fn decompress_sevenz<R>(reader: R, output_path: &Path, quiet: bool) -> crate::Result<usize>
|
||||
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)?;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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<usize>;
|
||||
let unpack_fn: Box<dyn FnOnce(&Path) -> 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();
|
||||
|
@ -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();
|
||||
|
@ -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";
|
||||
|
@ -22,7 +22,8 @@ use utils::{QuestionAction, QuestionPolicy};
|
||||
const BUFFER_CAPACITY: usize = 1024 * 32;
|
||||
|
||||
/// Current directory or empty directory
|
||||
static CURRENT_DIRECTORY: Lazy<PathBuf> = Lazy::new(|| std::fs::canonicalize(env::current_dir().unwrap_or_default()).unwrap_or_default());
|
||||
static CURRENT_DIRECTORY: Lazy<PathBuf> =
|
||||
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;
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user