diff --git a/Cargo.lock b/Cargo.lock index 57944a2..383670d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,7 +94,6 @@ dependencies = [ "indexmap", "lazy_static", "os_str_bytes", - "strsim 0.10.0", "termcolor", "terminal_size", "textwrap", @@ -187,7 +186,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim 0.9.3", + "strsim", "syn", ] @@ -561,12 +560,6 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - [[package]] name = "syn" version = "1.0.60" diff --git a/Cargo.toml b/Cargo.toml index ed42934..0421bb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,8 @@ snailquote = "0.3.0" [dependencies.clap] version = "3.0.0-beta.2" -features = ["wrap_help"] +default-features = false +features = ["wrap_help", "color", "derive", "std"] [dependencies.env_logger] version = "0.8.2" diff --git a/src/main.rs b/src/main.rs index 5a271bb..c985994 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,10 +28,10 @@ use log::{debug, trace, info, warn}; use rayon::prelude::*; use std::fmt::{self, Display}; use xdg_mime::SharedMimeInfo; +use std::io::stdout; use crate::parameters::OutputFormat; use crate::scanerror::ScanError; use crate::formats::{Script, Format}; -use std::io::stdout; pub struct Findings { file: PathBuf, @@ -102,43 +102,43 @@ fn extension_from_path(path: &Path) -> Option { } fn scan_file(db: &SharedMimeInfo, entry: &DirEntry) -> Result { - // try to determine mimetype for this entry - let result = inspectors::mime_type(db, entry.path()); + // try to determine mimetype for this entry + let result = inspectors::mime_type(db, entry.path()); - if result.is_err() { - // an error occurred while trying to read the file - // error!("{}: {}", entry.path().to_string_lossy(), error); - return Err((ScanError::File, entry.path().to_path_buf())); - } + if result.is_err() { + // an error occurred while trying to read the file + // error!("{}: {}", entry.path().to_string_lossy(), error); + return Err((ScanError::File, entry.path().to_path_buf())); + } - let result = result.unwrap(); - if result.is_none() { - // the file was read successfully, but we were unable to determine its mimetype - // warn!("Couldn't determine mimetype for {}", entry.path().to_string_lossy()); - return Err((ScanError::Mime, entry.path().to_path_buf())); - } + let result = result.unwrap(); + if result.is_none() { + // the file was read successfully, but we were unable to determine its mimetype + // warn!("Couldn't determine mimetype for {}", entry.path().to_string_lossy()); + return Err((ScanError::Mime, entry.path().to_path_buf())); + } - let result = result.unwrap(); + let result = result.unwrap(); - // set of known extensions for the given mimetype - let known_exts = inspectors::mime_extension_lookup(result.clone()); - // file extension for this particular file - let entry_ext = extension_from_path(entry.path()); + // set of known extensions for the given mimetype + let known_exts = inspectors::mime_extension_lookup(result.clone()); + // file extension for this particular file + let entry_ext = extension_from_path(entry.path()); - let valid = match known_exts { - // there is a known set of extensions for this mimetype, and the file has an extension - Some(e) if entry_ext.is_some() => e.contains(&entry_ext.unwrap().to_lowercase().into()), - // there is a known set of extensions for this mimetype, but the file has no extension - Some(_) => false, - // there is no known set of extensions for this mimetype -- assume it's correct - None => true - }; + let valid = match known_exts { + // there is a known set of extensions for this mimetype, and the file has an extension + Some(e) if entry_ext.is_some() => e.contains(&entry_ext.unwrap().to_lowercase().into()), + // there is a known set of extensions for this mimetype, but the file has no extension + Some(_) => false, + // there is no known set of extensions for this mimetype -- assume it's correct + None => true + }; - Ok(Findings { - file: entry.path().to_path_buf(), - valid, // make this a function - mime: result, - }) + Ok(Findings { + file: entry.path().to_path_buf(), + valid, // make this a function + mime: result, + }) } fn scan_from_walkdir(db: &SharedMimeInfo, entries: Vec) -> Vec> {