release v0.3.0!! \0u0/
This commit is contained in:
parent
4acbcaaa9b
commit
090e4adafe
7 changed files with 40 additions and 12 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -193,7 +193,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "fif"
|
||||
version = "0.2.13"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"cached",
|
||||
"cfg-if",
|
||||
|
|
|
@ -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 <lynne@bune.city>"]
|
||||
edition = "2018"
|
||||
license = "GPL-3.0-or-later"
|
||||
|
|
14
README.md
14
README.md
|
@ -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)
|
||||
](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.*
|
||||
</div>
|
||||
|
||||
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
|
||||
|
|
BIN
doc/screenshot.png
Normal file
BIN
doc/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -18,6 +18,6 @@ pub struct Findings<'a> {
|
|||
|
||||
impl<'a> Findings<'a> {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
11
src/main.rs
11
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<Result<Findings, ScanError>> {
|
|||
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<Vec<...>>
|
||||
chunk
|
||||
.iter() // iter over the chunk, which is a slice of DirEntry structs
|
||||
.map(|entry| scan_file(entry))
|
||||
.collect::<Vec<_>>()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue