report files renamed/skipped/failed in --fix mode
This commit is contained in:
parent
fcaaf283b7
commit
c0d8105731
3 changed files with 19 additions and 2 deletions
|
@ -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