release v0.3.0!! \0u0/
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Lynne Megido 2021-04-28 23:19:04 +10:00
parent 4acbcaaa9b
commit 090e4adafe
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
7 changed files with 40 additions and 12 deletions

2
Cargo.lock generated
View file

@ -193,7 +193,7 @@ dependencies = [
[[package]] [[package]]
name = "fif" name = "fif"
version = "0.2.13" version = "0.3.0"
dependencies = [ dependencies = [
"cached", "cached",
"cfg-if", "cfg-if",

View file

@ -1,7 +1,7 @@
[package] [package]
name = "fif" name = "fif"
description = "A command-line tool for detecting and optionally correcting files with incorrect extensions." description = "A command-line tool for detecting and optionally correcting files with incorrect extensions."
version = "0.2.13" version = "0.3.0"
authors = ["Lynnesbian <lynne@bune.city>"] authors = ["Lynnesbian <lynne@bune.city>"]
edition = "2018" edition = "2018"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"

View file

@ -1,5 +1,10 @@
fif <div align="center">fif</div>
=== ===
<div align="center">
![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) [![Version](https://img.shields.io/crates/v/fif.svg?logo=rust&style=flat-square)
](https://crates.io/crates/fif) ](https://crates.io/crates/fif)
[![Minimum Supported Rust Version](https://img.shields.io/badge/msrv-1.43.0-orange?logo=rust&style=flat-square) [![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) [![Unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg?style=flat-square)
](https://github.com/rust-secure-code/safety-dance/) ](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.*
</div>
fif recursively scans the given directory and outputs a shell script to fix the name of any files with incorrect 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. 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 cargo install --locked fif
``` ```
To update, simply re-run this command, or use a tool like To update, simply re-run this command, or use a tool like [cargo-update
[cargo-update](https://github.com/nabijaczleweli/cargo-update). ](https://github.com/nabijaczleweli/cargo-update).
#### Other backends #### Other backends
`fif` supports using [`infer`](https://crates.io/crates/infer) or [`xdg-mime`](https://crates.io/crates/xdg-mime) as its `fif` supports using [`infer`](https://crates.io/crates/infer) or [`xdg-mime`](https://crates.io/crates/xdg-mime) as its

BIN
doc/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -18,6 +18,6 @@ pub struct Findings<'a> {
impl<'a> Findings<'a> { impl<'a> Findings<'a> {
pub fn recommended_extension(&self) -> Option<String> { pub fn recommended_extension(&self) -> Option<String> {
mime_extension_lookup(self.mime.clone()).map(|extensions| extensions[0].to_owned()) mime_extension_lookup(self.mime.clone()).map(|extensions| extensions[0].clone())
} }
} }

View file

@ -74,6 +74,7 @@ fn main() {
// .target(env_logger::Target::Stdout) // log to stdout rather than stderr // .target(env_logger::Target::Stdout) // log to stdout rather than stderr
.init(); .init();
trace!("Initialise mimetype database");
init_db(); init_db();
debug!("Iterating directory: {:?}", args.dirs); debug!("Iterating directory: {:?}", args.dirs);
@ -121,6 +122,8 @@ fn main() {
) )
.collect(); .collect();
trace!("Scanning complete");
for result in &results { for result in &results {
match result { match result {
Ok(r) => { Ok(r) => {
@ -276,13 +279,11 @@ fn scan_from_walkdir(entries: &[DirEntry]) -> Vec<Result<Findings, ScanError>> {
if #[cfg(feature = "multi-threaded")] { if #[cfg(feature = "multi-threaded")] {
use rayon::prelude::*; use rayon::prelude::*;
// rather than using a standard par_iter, split the entries into chunks of 32 first. // split the entries into chunks of 32, and iterate over each chunk of entries in a separate thread
// 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
entries entries
.par_chunks(32) // split into chunks of 32 .par_chunks(32)
.flat_map(|chunk| { .flat_map(|chunk| {
chunk // return Vec<...> instead of Chunk<Vec<...>> chunk
.iter() // iter over the chunk, which is a slice of DirEntry structs .iter() // iter over the chunk, which is a slice of DirEntry structs
.map(|entry| scan_file(entry)) .map(|entry| scan_file(entry))
.collect::<Vec<_>>() .collect::<Vec<_>>()

View file

@ -387,3 +387,24 @@ fn writables_is_correct() {
writables!["henlo", (Path::new("henlo")), Newline, Space] 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)
}
}