Compare commits
4 commits
480acf515f
...
672cc8da90
Author | SHA1 | Date | |
---|---|---|---|
672cc8da90 | |||
c0d8105731 | |||
fcaaf283b7 | |||
36c0e99a92 |
9 changed files with 36 additions and 15 deletions
|
@ -37,6 +37,7 @@ stages:
|
||||||
script:
|
script:
|
||||||
- cargo install cargo-sweep
|
- cargo install cargo-sweep
|
||||||
- cargo sweep -i
|
- 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
|
# 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
|
# 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
|
- multi-threaded infer-backend
|
||||||
|
|
||||||
script:
|
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.
|
# test with various features on and off.
|
||||||
.cargo-test:
|
.cargo-test:
|
||||||
|
|
|
@ -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
|
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).
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## Unreleased
|
## v0.4.0 - 2021-10-14
|
||||||
### Added
|
### Added
|
||||||
- `--fix` mode - instead of outputting a shell script or text file, fif will rename the misnamed files for you!
|
- `--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
|
- 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
|
- 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
|
recommend an extension for, in order of filename, followed by files that fif knows how to rename, again in order
|
||||||
of filename.
|
of filename.
|
||||||
---
|
### Other
|
||||||
|
- [Reuse](https://reuse.software) compliance
|
||||||
|
|
||||||
## v0.3.7 - 2021-09-25
|
## v0.3.7 - 2021-09-25
|
||||||
### Added
|
### Added
|
||||||
|
|
18
Cargo.lock
generated
18
Cargo.lock
generated
|
@ -175,7 +175,7 @@ checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fif"
|
name = "fif"
|
||||||
version = "0.3.7"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"clap",
|
"clap",
|
||||||
|
@ -454,9 +454,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.29"
|
version = "1.0.30"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d"
|
checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
@ -648,9 +648,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.78"
|
version = "1.0.80"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4eac2e6c19f5c3abc0c229bea31ff0b9b091c7b14990e8924b92902a303a0c0"
|
checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -702,18 +702,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.29"
|
version = "1.0.30"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "602eca064b2d83369e2b2f34b09c70b605402801927c65c11071ac911d299b88"
|
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror-impl",
|
"thiserror-impl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror-impl"
|
name = "thiserror-impl"
|
||||||
version = "1.0.29"
|
version = "1.0.30"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c"
|
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
@ -4,7 +4,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.3.7"
|
version = "0.4.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"
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
](https://github.com/rust-secure-code/safety-dance/)
|
](https://github.com/rust-secure-code/safety-dance/)
|
||||||
[![Dependency versions](https://deps.rs/repo/gitlab/lynnesbian/fif/status.svg)
|
[![Dependency versions](https://deps.rs/repo/gitlab/lynnesbian/fif/status.svg)
|
||||||
](https://deps.rs/repo/gitlab/lynnesbian/fif)
|
](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.*
|
*A command-line tool for detecting and optionally correcting files with incorrect extensions.*
|
||||||
</div>
|
</div>
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
|
@ -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
|
/// 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(
|
pub fn scan_directory(
|
||||||
dirs: &Path,
|
dirs: &Path,
|
||||||
exts: Option<&BTreeSet<&str>>,
|
exts: Option<&BTreeSet<&str>>,
|
||||||
|
|
|
@ -316,7 +316,7 @@ impl FormatSteps for Text {
|
||||||
smart_write(
|
smart_write(
|
||||||
f,
|
f,
|
||||||
// writablesln![Newline, "Processed ", (entries.len().to_string().as_str()), " files"],
|
// writablesln![Newline, "Processed ", (entries.len().to_string().as_str()), " files"],
|
||||||
writablesln![Newline, "Done."],
|
&[Writable::Newline],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -147,6 +147,10 @@ fn main() {
|
||||||
|
|
||||||
let prompt = args.prompt.unwrap_or(Prompt::Error);
|
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 {
|
for f in findings {
|
||||||
if let Some(rename_to) = f.recommended_path() {
|
if let Some(rename_to) = f.recommended_path() {
|
||||||
let will_rename = {
|
let will_rename = {
|
||||||
|
@ -171,13 +175,16 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if !will_rename {
|
if !will_rename {
|
||||||
|
skipped += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
// until file is renamed successfully
|
||||||
match std::fs::rename(&f.file, &rename_to) {
|
match std::fs::rename(&f.file, &rename_to) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Renamed {:#?} -> {:#?}", f.file, rename_to);
|
info!("Renamed {:#?} -> {:#?}", f.file, rename_to);
|
||||||
|
renamed += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -185,6 +192,7 @@ fn main() {
|
||||||
// if the user passed --prompt never, continue to the next file
|
// 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"
|
// 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)) {
|
if prompt == Prompt::Never || !ask(&*format!("Error while renaming file: {:#?}. Try again?", e)) {
|
||||||
|
failed += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,8 +201,17 @@ fn main() {
|
||||||
} else {
|
} else {
|
||||||
// no recommended name :c
|
// no recommended name :c
|
||||||
info!("No known extension for file {:#?} of type {}", f.file, f.mime);
|
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 {
|
} else {
|
||||||
let mut buffered_stdout = BufWriter::new(stdout());
|
let mut buffered_stdout = BufWriter::new(stdout());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue