Truncate --log file on open instead of appending

Each scpcap invocation now starts its log fresh. Appending meant a re-run
after a failed attempt mixed new output in with (or could be mistaken for)
stale output from the previous run -- confusing when diagnosing exactly
this kind of issue in production.
This commit is contained in:
2026-08-28 09:47:27 -04:00
parent 738ac26210
commit bc2ee2d374
+4 -1
View File
@@ -15,8 +15,11 @@ impl Logger {
Logger(None)
}
/// Truncates any existing file at `path` -- each run starts a fresh
/// log, so a re-run never leaves stale lines from a previous attempt
/// mixed in with (or mistaken for) the current one.
pub fn open(path: &Path) -> std::io::Result<Logger> {
let f = OpenOptions::new().create(true).append(true).open(path)?;
let f = OpenOptions::new().create(true).write(true).truncate(true).open(path)?;
Ok(Logger(Some(Mutex::new(f))))
}