diff --git a/src/commands.rs b/src/commands.rs index f4bc513..688c91d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -22,7 +22,7 @@ use crate::{ info, list::{self, ListOptions}, utils::{ - self, concatenate_list_of_os_str, dir_is_empty, nice_directory_display, to_utf, try_infer, + self, concatenate_list_of_os_str, dir_is_empty, nice_directory_display, to_utf, try_infer_extension, user_wants_to_continue_decompressing, }, warning, Opts, QuestionPolicy, Subcommand, @@ -495,7 +495,7 @@ fn check_mime_type( if format.is_empty() { // File with no extension // Try to detect it automatically and prompt the user about it - if let Some(detected_format) = try_infer(path) { + if let Some(detected_format) = try_infer_extension(path) { info!("Detected file: `{}` extension as `{}`", path.display(), detected_format); if user_wants_to_continue_decompressing(path, question_policy)? { format.push(detected_format); @@ -503,7 +503,7 @@ fn check_mime_type( return Ok(ControlFlow::Break(())); } } - } else if let Some(detected_format) = try_infer(path) { + } else if let Some(detected_format) = try_infer_extension(path) { // File ending with extension // Try to detect the extension and warn the user if it differs from the written one let outer_ext = format.iter().next().unwrap(); diff --git a/src/utils/fs.rs b/src/utils/fs.rs index 11332a9..86f49d4 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -4,6 +4,8 @@ use std::{ borrow::Cow, env, ffi::OsStr, + fs::ReadDir, + io::Read, path::{Component, Path, PathBuf}, }; @@ -13,7 +15,7 @@ use crate::{extension::Extension, info}; /// Checks given path points to an empty directory. pub fn dir_is_empty(dir_path: &Path) -> bool { - let is_empty = |mut rd: std::fs::ReadDir| rd.next().is_none(); + let is_empty = |mut rd: ReadDir| rd.next().is_none(); dir_path.read_dir().map(is_empty).unwrap_or_default() } @@ -82,7 +84,7 @@ pub fn nice_directory_display(os_str: impl AsRef) -> Cow<'static, str> { /// Try to detect the file extension by looking for known magic strings /// Source: https://en.wikipedia.org/wiki/List_of_file_signatures -pub fn try_infer(path: &Path) -> Option { +pub fn try_infer_extension(path: &Path) -> Option { fn is_zip(buf: &[u8]) -> bool { buf.len() > 3 && buf[0] == 0x50 @@ -155,10 +157,12 @@ pub fn try_infer(path: &Path) -> Option { /// Module with a list of bright colors. #[allow(dead_code)] pub mod colors { + use std::env; + use once_cell::sync::Lazy; static DISABLE_COLORED_TEXT: Lazy = Lazy::new(|| { - std::env::var_os("NO_COLOR").is_some() || atty::isnt(atty::Stream::Stdout) || atty::isnt(atty::Stream::Stderr) + env::var_os("NO_COLOR").is_some() || atty::isnt(atty::Stream::Stdout) || atty::isnt(atty::Stream::Stderr) }); macro_rules! color { diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 4b3bee3..8b147bf 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -5,10 +5,5 @@ mod fs; mod question_policy; pub use bytes::Bytes; -pub use fs::{ - cd_into_same_dir_as, colors, concatenate_list_of_os_str, create_dir_if_non_existent, dir_is_empty, - nice_directory_display, strip_cur_dir, to_utf, try_infer, -}; -pub use question_policy::{ - create_or_ask_overwrite, user_wants_to_continue_decompressing, user_wants_to_overwrite, QuestionPolicy, -}; +pub use fs::*; +pub use question_policy::*;