From 2e6cd893dcde49fbb0cf7bb8719abf0069003edb Mon Sep 17 00:00:00 2001 From: TATSUNO Yasuhiro Date: Wed, 20 Oct 2021 00:57:11 +0900 Subject: [PATCH 1/6] Omit "./" at the start of the path (#109) --- src/archive/zip.rs | 2 ++ src/utils.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/archive/zip.rs b/src/archive/zip.rs index be47ea8..67d3118 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -3,6 +3,7 @@ use std::{ env, fs, io::{self, prelude::*}, + path::Component, path::{Path, PathBuf}, }; @@ -47,6 +48,7 @@ where fs::create_dir_all(&path)?; } } + let file_path = file_path.strip_prefix(Component::CurDir).unwrap_or_else(|_| file_path.as_path()); info!("{:?} extracted. ({})", file_path.display(), Bytes::new(file.size())); diff --git a/src/utils.rs b/src/utils.rs index 71e0337..4a5d617 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,6 +2,7 @@ use std::{ cmp, env, ffi::OsStr, fs::{self, ReadDir}, + path::Component, path::{Path, PathBuf}, }; @@ -45,6 +46,7 @@ pub fn user_wants_to_overwrite(path: &Path, flags: &oof::Flags) -> crate::Result _ => {} } + let path = path.strip_prefix(Component::CurDir).unwrap_or_else(|_| path); Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE")).ask(Some(&to_utf(path))) } From 13aad5db87b5cfb24b577b4bcecd2cd048de5ba1 Mon Sep 17 00:00:00 2001 From: figsoda Date: Tue, 19 Oct 2021 14:13:07 -0400 Subject: [PATCH 2/6] Add repology badge to README (#113) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index cba6af6..db008da 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ ouch compress * everything.tar.gz.xz.bz.zst.gz.gz.gz.gz.gz ## Installation +[![Packaging status](https://repology.org/badge/vertical-allrepos/ouch.svg)](https://repology.org/project/ouch/versions) + ### Downloading the latest binary Compiled for `x86_64` on _Linux_, _Mac OS_ and _Windows_, run with `curl` or `wget`. From b8a2c3899e4e90ff4fbe3fa175f301a31a514978 Mon Sep 17 00:00:00 2001 From: TATSUNO Yasuhiro Date: Wed, 20 Oct 2021 10:54:14 +0900 Subject: [PATCH 3/6] Use a same term as in command --- src/commands.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index de2722d..66408c6 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -318,7 +318,7 @@ fn decompress_file( utils::create_dir_if_non_existent(output_folder)?; let zip_archive = zip::ZipArchive::new(reader)?; let _files = crate::archive::zip::unpack_archive(zip_archive, output_folder, flags)?; - info!("Successfully uncompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); return Ok(()); } @@ -352,31 +352,31 @@ fn decompress_file( let mut writer = fs::File::create(&output_path)?; io::copy(&mut reader, &mut writer)?; - info!("Successfully uncompressed archive in '{}'.", to_utf(output_path)); + info!("Successfully decompressed archive in '{}'.", to_utf(output_path)); } Tar => { let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?; - info!("Successfully uncompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); } Tgz => { let reader = chain_reader_decoder(&Gzip, reader)?; let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?; - info!("Successfully uncompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); } Tbz => { let reader = chain_reader_decoder(&Bzip, reader)?; let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?; - info!("Successfully uncompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); } Tlzma => { let reader = chain_reader_decoder(&Lzma, reader)?; let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?; - info!("Successfully uncompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); } Tzst => { let reader = chain_reader_decoder(&Zstd, reader)?; let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?; - info!("Successfully uncompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); } Zip => { eprintln!("Compressing first into .zip."); @@ -392,7 +392,7 @@ fn decompress_file( let _ = crate::archive::zip::unpack_archive(zip_archive, output_folder, flags)?; - info!("Successfully uncompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); } } From 5f7d77734245c0d65d88fdaf9a30178d605fa672 Mon Sep 17 00:00:00 2001 From: TATSUNO Yasuhiro Date: Wed, 20 Oct 2021 12:57:11 +0900 Subject: [PATCH 4/6] Change display of current directory (#119) --- src/commands.rs | 17 +++++++++-------- src/utils.rs | 9 +++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 66408c6..c6fc62d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -19,6 +19,7 @@ use crate::{ CompressionFormat::{self, *}, }, info, oof, + utils::nice_directory_display, utils::to_utf, utils::{self, dir_is_empty}, Error, @@ -318,7 +319,7 @@ fn decompress_file( utils::create_dir_if_non_existent(output_folder)?; let zip_archive = zip::ZipArchive::new(reader)?; let _files = crate::archive::zip::unpack_archive(zip_archive, output_folder, flags)?; - info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder)); return Ok(()); } @@ -352,31 +353,31 @@ fn decompress_file( let mut writer = fs::File::create(&output_path)?; io::copy(&mut reader, &mut writer)?; - info!("Successfully decompressed archive in '{}'.", to_utf(output_path)); + info!("Successfully decompressed archive in {}.", nice_directory_display(output_path)); } Tar => { let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?; - info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder)); } Tgz => { let reader = chain_reader_decoder(&Gzip, reader)?; let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?; - info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder)); } Tbz => { let reader = chain_reader_decoder(&Bzip, reader)?; let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?; - info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder)); } Tlzma => { let reader = chain_reader_decoder(&Lzma, reader)?; let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?; - info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder)); } Tzst => { let reader = chain_reader_decoder(&Zstd, reader)?; let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?; - info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder)); } Zip => { eprintln!("Compressing first into .zip."); @@ -392,7 +393,7 @@ fn decompress_file( let _ = crate::archive::zip::unpack_archive(zip_archive, output_folder, flags)?; - info!("Successfully decompressed archive in '{}'.", to_utf(output_folder)); + info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder)); } } diff --git a/src/utils.rs b/src/utils.rs index 4a5d617..01fe9c1 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -55,6 +55,15 @@ pub fn to_utf(os_str: impl AsRef) -> String { text.trim_matches('"').to_string() } +pub fn nice_directory_display(os_str: impl AsRef) -> String { + let text = to_utf(os_str); + if text == "." { + "current directory".to_string() + } else { + format!("'{}'", text) + } +} + pub struct Bytes { bytes: f64, } From 4404b91a23f7b64c391b6745a5aa2bce7e804b9b Mon Sep 17 00:00:00 2001 From: TATSUNO Yasuhiro Date: Wed, 20 Oct 2021 13:10:10 +0900 Subject: [PATCH 5/6] refactoring: Extract function (#116) --- src/archive/zip.rs | 5 ++--- src/utils.rs | 9 ++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 67d3118..f2f1d2f 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -3,7 +3,6 @@ use std::{ env, fs, io::{self, prelude::*}, - path::Component, path::{Path, PathBuf}, }; @@ -12,7 +11,7 @@ use zip::{self, read::ZipFile, ZipArchive}; use crate::{ info, oof, - utils::{self, dir_is_empty, Bytes}, + utils::{self, dir_is_empty, strip_cur_dir, Bytes}, }; use self::utf8::get_invalid_utf8_paths; @@ -48,7 +47,7 @@ where fs::create_dir_all(&path)?; } } - let file_path = file_path.strip_prefix(Component::CurDir).unwrap_or_else(|_| file_path.as_path()); + let file_path = strip_cur_dir(file_path.as_path()); info!("{:?} extracted. ({})", file_path.display(), Bytes::new(file.size())); diff --git a/src/utils.rs b/src/utils.rs index 01fe9c1..75ff57c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -23,6 +23,13 @@ pub fn create_dir_if_non_existent(path: &Path) -> crate::Result<()> { Ok(()) } +pub fn strip_cur_dir(source_path: &Path) -> PathBuf { + source_path + .strip_prefix(Component::CurDir) + .map(|path| path.to_path_buf()) + .unwrap_or_else(|_| source_path.to_path_buf()) +} + /// Changes the process' current directory to the directory that contains the /// file pointed to by `filename` and returns the directory that the process /// was in before this function was called. @@ -46,7 +53,7 @@ pub fn user_wants_to_overwrite(path: &Path, flags: &oof::Flags) -> crate::Result _ => {} } - let path = path.strip_prefix(Component::CurDir).unwrap_or_else(|_| path); + let path = strip_cur_dir(path); Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE")).ask(Some(&to_utf(path))) } From d533af27d4898a4eb641ba0702f6883bce32fe1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos=20Bezerra?= Date: Wed, 20 Oct 2021 08:30:12 -0300 Subject: [PATCH 6/6] README: add "no runtime dependencies" as a feature Currently only supported by Linux on x86_64 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index db008da..4ab33f7 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ 2. Automatic format detection. 3. Same syntax, various formats. 4. Encoding and decoding streams, it's fast. +5. No runtime dependencies (for _Linux x86_64_). ## Usage