From c8989cb80ce744c57f79d7b88096248a89676f93 Mon Sep 17 00:00:00 2001 From: tinger Date: Fri, 31 Oct 2025 20:20:31 +0100 Subject: [PATCH] control: Allow aborting with empty file Of note is that empty here means "no filenames", but in most cases selecting everything and removing it is the easiest way to get an empty file. --- src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.rs b/src/main.rs index 789c48d..b4a15b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,6 +61,7 @@ fn main_impl() -> Result> { let mut buffer = vec![]; // write header and paths + writeln!(buffer, "// clear the file to abort the rename")?; writeln!(buffer, "// empty lines and coments are ignored")?; writeln!(buffer, "// do not remove or reorder any lines")?; writeln!(buffer, "// do not edit anything other than file stems")?; @@ -99,6 +100,11 @@ fn main_impl() -> Result> { drop(file); + if after.is_empty() { + eprintln!("file empty, aborted rename"); + return Ok(ExitCode::FAILURE); + } + if before.len() != after.len() { eprintln!( "had {} path(s) before, but {} path(s) after", -- 2.51.2