From 786b746044164cfa1f15fab7ff4687f8b55a2505 Mon Sep 17 00:00:00 2001 From: pierre Date: Thu, 19 Sep 2024 21:30:43 +0200 Subject: [PATCH] refactor: use fs rename for log file rotation --- src/trace.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/trace.rs b/src/trace.rs index db02766..04e3864 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -22,19 +22,12 @@ fn rotate_log_file(log_dir: PathBuf) -> Result<()> { let log_file = log_dir.join(LOG_FILE); if log_file.is_file() { let old_file = log_dir.join(LOG_FILE_OLD); - let data = fs::read(&log_file).inspect_err(|e| { + fs::rename(&log_file, &old_file).inspect_err(|e| { eprintln!( - "failed to read log file during log rotation {}: {e}", + "failed to rename log file during log rotation {}: {e}", log_file.display() ) })?; - fs::write(&old_file, data).inspect_err(|e| { - eprintln!( - "failed to write log file during log rotation {}: {e}", - old_file.display() - ) - })?; - fs::remove_file(log_file)?; } Ok(()) }