diff --git a/Cargo.lock b/Cargo.lock index 54afde4..f3d30e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -193,7 +193,7 @@ dependencies = [ [[package]] name = "fif" -version = "0.2.13" +version = "0.3.0" dependencies = [ "cached", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index 47c9a7b..6dab421 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "fif" description = "A command-line tool for detecting and optionally correcting files with incorrect extensions." -version = "0.2.13" +version = "0.3.0" authors = ["Lynnesbian "] edition = "2018" license = "GPL-3.0-or-later" diff --git a/README.md b/README.md index 973a4bb..5d1f3b4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ -fif +
fif
=== +
+ +![A screenshot demonstrating fif's ability to detect the correct file extensions for a few files. +](https://gitlab.com/Lynnesbian/fif/-/blob/master/doc/screenshot.png) + [![Version](https://img.shields.io/crates/v/fif.svg?logo=rust&style=flat-square) ](https://crates.io/crates/fif) [![Minimum Supported Rust Version](https://img.shields.io/badge/msrv-1.43.0-orange?logo=rust&style=flat-square) @@ -13,7 +18,8 @@ fif [![Unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg?style=flat-square) ](https://github.com/rust-secure-code/safety-dance/) -A command-line tool for detecting and optionally correcting files with incorrect extensions. +*A command-line tool for detecting and optionally correcting files with incorrect extensions.* +
fif recursively scans the given directory and outputs a shell script to fix the name of any files with incorrect extensions. By default, fif will scan all non-hidden files in the given directory, and will ignore symlinks. @@ -29,8 +35,8 @@ that it's not doing anything that will give you a headache before running it. cargo install --locked fif ``` -To update, simply re-run this command, or use a tool like -[cargo-update](https://github.com/nabijaczleweli/cargo-update). +To update, simply re-run this command, or use a tool like [cargo-update +](https://github.com/nabijaczleweli/cargo-update). #### Other backends `fif` supports using [`infer`](https://crates.io/crates/infer) or [`xdg-mime`](https://crates.io/crates/xdg-mime) as its diff --git a/doc/screenshot.png b/doc/screenshot.png new file mode 100644 index 0000000..0297739 Binary files /dev/null and b/doc/screenshot.png differ diff --git a/src/findings.rs b/src/findings.rs index c24ebf4..63699ea 100644 --- a/src/findings.rs +++ b/src/findings.rs @@ -18,6 +18,6 @@ pub struct Findings<'a> { impl<'a> Findings<'a> { pub fn recommended_extension(&self) -> Option { - mime_extension_lookup(self.mime.clone()).map(|extensions| extensions[0].to_owned()) + mime_extension_lookup(self.mime.clone()).map(|extensions| extensions[0].clone()) } } diff --git a/src/main.rs b/src/main.rs index 2a07ded..93832ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,6 +74,7 @@ fn main() { // .target(env_logger::Target::Stdout) // log to stdout rather than stderr .init(); + trace!("Initialise mimetype database"); init_db(); debug!("Iterating directory: {:?}", args.dirs); @@ -121,6 +122,8 @@ fn main() { ) .collect(); + trace!("Scanning complete"); + for result in &results { match result { Ok(r) => { @@ -276,13 +279,11 @@ fn scan_from_walkdir(entries: &[DirEntry]) -> Vec> { if #[cfg(feature = "multi-threaded")] { use rayon::prelude::*; - // rather than using a standard par_iter, split the entries into chunks of 32 first. - // this allows each spawned thread to handle 32 files before before closing, rather than creating a new thread for - // each file. this leads to a pretty substantial speedup that i'm pretty substantially happy about 0u0 + // split the entries into chunks of 32, and iterate over each chunk of entries in a separate thread entries - .par_chunks(32) // split into chunks of 32 + .par_chunks(32) .flat_map(|chunk| { - chunk // return Vec<...> instead of Chunk> + chunk .iter() // iter over the chunk, which is a slice of DirEntry structs .map(|entry| scan_file(entry)) .collect::>() diff --git a/src/tests/mod.rs b/src/tests/mod.rs index c97bc14..5983882 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -387,3 +387,24 @@ fn writables_is_correct() { writables!["henlo", (Path::new("henlo")), Newline, Space] ) } + +#[test] +/// Test various combinations of verbosity flags. +fn verbosity() { + assert!(Parameters::try_parse_from(&["fif", "-q", "-v"]).is_err(), "Failed to reject usage of both -q and -v!"); + + let mut expected_results = HashMap::new(); + expected_results.insert("-qqqqqqqq", "off"); + expected_results.insert("-qqq", "off"); + expected_results.insert("-qq", "error"); + expected_results.insert("-q", "warn"); + expected_results.insert("-s", "info"); + expected_results.insert("-v", "debug"); + expected_results.insert("-vv", "trace"); + expected_results.insert("-vvv", "trace"); + expected_results.insert("-vvvvvvvv", "trace"); + + for (flags, level) in expected_results { + assert_eq!(Parameters::parse_from(&["fif", flags]).default_verbosity(), level) + } +}