Compare commits

..

4 commits

9 changed files with 36 additions and 15 deletions

View file

@ -37,6 +37,7 @@ stages:
script:
- cargo install cargo-sweep
- cargo sweep -i
- git -C $CI_PROJECT_DIR/.cargo/registry/index/github.com-1ecc6299db9ec823/ gc || true
# this builds a "base" version of fif with default features enabled. this is done separately from the main build step
# for the purposes of caching - by building once *before* executing the parallel cargo-build step, we ensure that
@ -59,7 +60,7 @@ stages:
- multi-threaded infer-backend
script:
cargo build --no-default-features --locked --features="json $FEATURES"
cargo run --no-default-features --locked --features="json $FEATURES" -- --version
# test with various features on and off.
.cargo-test:

View file

@ -4,7 +4,7 @@ Dates are given in YYYY-MM-DD format - for example, the 15th of October 2021 is
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
## v0.4.0 - 2021-10-14
### Added
- `--fix` mode - instead of outputting a shell script or text file, fif will rename the misnamed files for you!
- By default, the user will be prompted only if fif encounters an error while renaming the file, or if renaming
@ -23,7 +23,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Output is now sorted by filename - specifically, errors will appear first, followed by files that fif is unable to
recommend an extension for, in order of filename, followed by files that fif knows how to rename, again in order
of filename.
---
### Other
- [Reuse](https://reuse.software) compliance
## v0.3.7 - 2021-09-25
### Added

18
Cargo.lock generated
View file

@ -175,7 +175,7 @@ checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193"
[[package]]
name = "fif"
version = "0.3.7"
version = "0.4.0"
dependencies = [
"cfg-if",
"clap",
@ -454,9 +454,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.29"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d"
checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70"
dependencies = [
"unicode-xid",
]
@ -648,9 +648,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "syn"
version = "1.0.78"
version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4eac2e6c19f5c3abc0c229bea31ff0b9b091c7b14990e8924b92902a303a0c0"
checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
dependencies = [
"proc-macro2",
"quote",
@ -702,18 +702,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.29"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "602eca064b2d83369e2b2f34b09c70b605402801927c65c11071ac911d299b88"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.29"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
dependencies = [
"proc-macro2",
"quote",

View file

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

View file

@ -17,6 +17,8 @@
](https://github.com/rust-secure-code/safety-dance/)
[![Dependency versions](https://deps.rs/repo/gitlab/lynnesbian/fif/status.svg)
](https://deps.rs/repo/gitlab/lynnesbian/fif)
[![REUSE status](https://api.reuse.software/badge/gitlab.com/Lynnesbian/fif/)
](https://api.reuse.software/info/gitlab.com/Lynnesbian/fif/)
*A command-line tool for detecting and optionally correcting files with incorrect extensions.*
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

View file

@ -183,7 +183,7 @@ pub fn scan_from_walkdir(
}
/// Scans a given directory with [`WalkDir`], filters with [`wanted_file`], checks for errors, and returns a vector of
/// [DirEntry]s.
/// [`DirEntry`]s.
pub fn scan_directory(
dirs: &Path,
exts: Option<&BTreeSet<&str>>,

View file

@ -316,7 +316,7 @@ impl FormatSteps for Text {
smart_write(
f,
// writablesln![Newline, "Processed ", (entries.len().to_string().as_str()), " files"],
writablesln![Newline, "Done."],
&[Writable::Newline],
)
}
}

View file

@ -147,6 +147,10 @@ fn main() {
let prompt = args.prompt.unwrap_or(Prompt::Error);
let mut renamed = 0_u32; // files that were successfully renamed
let mut skipped = 0_u32; // files that were skipped over without trying to rename
let mut failed = 0_u32; // files that fif failed to rename - e.g. files that are exclusively locked
for f in findings {
if let Some(rename_to) = f.recommended_path() {
let will_rename = {
@ -171,13 +175,16 @@ fn main() {
};
if !will_rename {
skipped += 1;
continue;
}
loop {
// until file is renamed successfully
match std::fs::rename(&f.file, &rename_to) {
Ok(_) => {
info!("Renamed {:#?} -> {:#?}", f.file, rename_to);
renamed += 1;
break;
}
Err(e) => {
@ -185,6 +192,7 @@ fn main() {
// if the user passed --prompt never, continue to the next file
// otherwise, prompt user to retry move, retrying until the rename succeeds or they respond "N"
if prompt == Prompt::Never || !ask(&*format!("Error while renaming file: {:#?}. Try again?", e)) {
failed += 1;
break;
}
}
@ -193,8 +201,17 @@ fn main() {
} else {
// no recommended name :c
info!("No known extension for file {:#?} of type {}", f.file, f.mime);
skipped += 1;
}
}
info!(
"Processed {} files: Renamed {}, skipped {}, failed to rename {}",
renamed + skipped + failed,
renamed,
skipped,
failed
);
} else {
let mut buffered_stdout = BufWriter::new(stdout());