Browse Source

report files renamed/skipped/failed in --fix mode

master
Lynne Megido 2 months ago
parent
commit
c0d8105731
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
  1. 2
      src/files.rs
  2. 2
      src/formats.rs
  3. 17
      src/main.rs

2
src/files.rs

@ -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>>,

2
src/formats.rs

@ -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],
)
}
}

17
src/main.rs

@ -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());

Loading…
Cancel
Save