mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 19:45:29 +00:00
chore: cargo fmt
This commit is contained in:
parent
633d1dedd0
commit
69b1db4a35
@ -2,14 +2,15 @@
|
|||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
fs::File,
|
fs::File,
|
||||||
path::{Path, PathBuf}, io::{Write, Seek, Read},
|
io::{Read, Seek, Write},
|
||||||
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use same_file::Handle;
|
use same_file::Handle;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
info,
|
info,
|
||||||
utils::{self, cd_into_same_dir_as, EscapedPathDisplay, FileVisibilityPolicy, Bytes},
|
utils::{self, cd_into_same_dir_as, Bytes, EscapedPathDisplay, FileVisibilityPolicy},
|
||||||
warning,
|
warning,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -21,8 +22,8 @@ pub fn compress_sevenz<W>(
|
|||||||
quiet: bool,
|
quiet: bool,
|
||||||
) -> crate::Result<W>
|
) -> crate::Result<W>
|
||||||
where
|
where
|
||||||
W: Write + Seek {
|
W: Write + Seek,
|
||||||
|
{
|
||||||
let mut writer = sevenz_rust::SevenZWriter::new(writer).map_err(crate::Error::SevenzipError)?;
|
let mut writer = sevenz_rust::SevenZWriter::new(writer).map_err(crate::Error::SevenzipError)?;
|
||||||
let output_handle = Handle::from_path(output_path);
|
let output_handle = Handle::from_path(output_path);
|
||||||
for filename in files {
|
for filename in files {
|
||||||
@ -92,7 +93,9 @@ W: Write + Seek {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn decompress_sevenz<R>(reader: R, output_path: &Path, quiet: bool) -> crate::Result<usize>
|
pub fn decompress_sevenz<R>(reader: R, output_path: &Path, quiet: bool) -> crate::Result<usize>
|
||||||
where R: Read+ Seek {
|
where
|
||||||
|
R: Read + Seek,
|
||||||
|
{
|
||||||
let mut count: usize = 0;
|
let mut count: usize = 0;
|
||||||
sevenz_rust::decompress_with_extract_fn(reader, output_path, |entry, reader, dest| {
|
sevenz_rust::decompress_with_extract_fn(reader, output_path, |entry, reader, dest| {
|
||||||
count += 1;
|
count += 1;
|
||||||
@ -104,13 +107,18 @@ where R: Read+ Seek {
|
|||||||
let file_path = output_path.join(entry.name());
|
let file_path = output_path.join(entry.name());
|
||||||
|
|
||||||
if entry.is_directory() {
|
if entry.is_directory() {
|
||||||
// This is printed for every file in the archive and has little
|
// This is printed for every file in the archive and has little
|
||||||
// importance for most users, but would generate lots of
|
// importance for most users, but would generate lots of
|
||||||
// spoken text for users using screen readers, braille displays
|
// spoken text for users using screen readers, braille displays
|
||||||
// and so on
|
// and so on
|
||||||
if !quiet {
|
if !quiet {
|
||||||
info!(inaccessible, "File {} extracted to \"{}\"", entry.name(), file_path.display());
|
info!(
|
||||||
}
|
inaccessible,
|
||||||
|
"File {} extracted to \"{}\"",
|
||||||
|
entry.name(),
|
||||||
|
file_path.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
let dir = dest;
|
let dir = dest;
|
||||||
if !dir.exists() {
|
if !dir.exists() {
|
||||||
std::fs::create_dir_all(dir)?;
|
std::fs::create_dir_all(dir)?;
|
||||||
|
@ -5,6 +5,7 @@ use std::{
|
|||||||
|
|
||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
|
|
||||||
|
use super::warn_user_about_loading_sevenz_in_memory;
|
||||||
use crate::{
|
use crate::{
|
||||||
archive,
|
archive,
|
||||||
commands::warn_user_about_loading_zip_in_memory,
|
commands::warn_user_about_loading_zip_in_memory,
|
||||||
@ -13,8 +14,6 @@ use crate::{
|
|||||||
QuestionAction, QuestionPolicy, BUFFER_CAPACITY,
|
QuestionAction, QuestionPolicy, BUFFER_CAPACITY,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::warn_user_about_loading_sevenz_in_memory;
|
|
||||||
|
|
||||||
/// Compress files into `output_file`.
|
/// Compress files into `output_file`.
|
||||||
///
|
///
|
||||||
/// # Arguments:
|
/// # Arguments:
|
||||||
@ -123,13 +122,12 @@ pub fn compress_files(
|
|||||||
)?;
|
)?;
|
||||||
vec_buffer.rewind()?;
|
vec_buffer.rewind()?;
|
||||||
io::copy(&mut vec_buffer, &mut writer)?;
|
io::copy(&mut vec_buffer, &mut writer)?;
|
||||||
},
|
}
|
||||||
Rar => {
|
Rar => {
|
||||||
archive::rar::no_compression_notice();
|
archive::rar::no_compression_notice();
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
},
|
}
|
||||||
SevenZip => {
|
SevenZip => {
|
||||||
|
|
||||||
if !formats.is_empty() {
|
if !formats.is_empty() {
|
||||||
warn_user_about_loading_sevenz_in_memory();
|
warn_user_about_loading_sevenz_in_memory();
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use std::{
|
|||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
|
|
||||||
use crate::{
|
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::{
|
extension::{
|
||||||
split_first_compression_format,
|
split_first_compression_format,
|
||||||
CompressionFormat::{self, *},
|
CompressionFormat::{self, *},
|
||||||
@ -145,7 +145,7 @@ pub fn decompress_file(
|
|||||||
} else {
|
} else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Rar => {
|
Rar => {
|
||||||
type UnpackResult = crate::Result<usize>;
|
type UnpackResult = crate::Result<usize>;
|
||||||
let unpack_fn: Box<dyn FnOnce(&Path) -> UnpackResult> = if formats.len() > 1 {
|
let unpack_fn: Box<dyn FnOnce(&Path) -> UnpackResult> = if formats.len() > 1 {
|
||||||
@ -163,7 +163,7 @@ pub fn decompress_file(
|
|||||||
} else {
|
} else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
SevenZip => {
|
SevenZip => {
|
||||||
if formats.len() > 1 {
|
if formats.len() > 1 {
|
||||||
warn_user_about_loading_sevenz_in_memory();
|
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))?;
|
let zip_archive = zip::ZipArchive::new(io::Cursor::new(vec))?;
|
||||||
|
|
||||||
Box::new(crate::archive::zip::list_archive(zip_archive))
|
Box::new(crate::archive::zip::list_archive(zip_archive))
|
||||||
},
|
}
|
||||||
Rar => {
|
Rar => {
|
||||||
if formats.len() > 1 {
|
if formats.len() > 1 {
|
||||||
let mut temp_file = tempfile::NamedTempFile::new()?;
|
let mut temp_file = tempfile::NamedTempFile::new()?;
|
||||||
@ -86,7 +86,7 @@ pub fn list_archive_contents(
|
|||||||
} else {
|
} else {
|
||||||
Box::new(crate::archive::rar::list_archive(archive_path))
|
Box::new(crate::archive::rar::list_archive(archive_path))
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
SevenZip => {
|
SevenZip => {
|
||||||
if formats.len() > 1 {
|
if formats.len() > 1 {
|
||||||
warn_user_about_loading_zip_in_memory();
|
warn_user_about_loading_zip_in_memory();
|
||||||
|
@ -7,7 +7,9 @@ use bstr::ByteSlice;
|
|||||||
use self::CompressionFormat::*;
|
use self::CompressionFormat::*;
|
||||||
use crate::{error::Error, warning};
|
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 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_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";
|
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;
|
const BUFFER_CAPACITY: usize = 1024 * 32;
|
||||||
|
|
||||||
/// Current directory or empty directory
|
/// 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
|
/// The status code returned from `ouch` on error
|
||||||
pub const EXIT_FAILURE: i32 = libc::EXIT_FAILURE;
|
pub const EXIT_FAILURE: i32 = libc::EXIT_FAILURE;
|
||||||
|
@ -84,7 +84,6 @@ fn ui_test_err_decompress_missing_extension() {
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
run_in(dir, "cmd", "/C copy nul b.unknown").unwrap();
|
run_in(dir, "cmd", "/C copy nul b.unknown").unwrap();
|
||||||
|
|
||||||
|
|
||||||
ui!(run_ouch("ouch decompress a", dir));
|
ui!(run_ouch("ouch decompress a", dir));
|
||||||
ui!(run_ouch("ouch decompress a b.unknown", dir));
|
ui!(run_ouch("ouch decompress a b.unknown", dir));
|
||||||
ui!(run_ouch("ouch decompress b.unknown", dir));
|
ui!(run_ouch("ouch decompress b.unknown", dir));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user