From 3aade17125aee3980edd01c783783292e915c5b1 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 2 Nov 2020 18:31:31 +0100 Subject: [PATCH] tools: log rotate: compressing rotated files We renamed the last one always to a file without compression extension, even if it was .zst previously. So always add the correct ending to the new last one, if compress was true. Further, we cannot detect if there'd be a compression required if we rotated (renamed) it already to the file with .zst included. So check on rotation itself if it would be a "no .zst" -> ",zst" transition, and call compress there. it really should be OK now *knocking wood* Signed-off-by: Thomas Lamprecht --- src/tools/logrotate.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/tools/logrotate.rs b/src/tools/logrotate.rs index 3f2e32c7..86415e86 100644 --- a/src/tools/logrotate.rs +++ b/src/tools/logrotate.rs @@ -95,21 +95,21 @@ impl LogRotate { let mut next_filename = self.base_path.clone().canonicalize()?.into_os_string(); next_filename.push(format!(".{}", filenames.len())); + if self.compress { + next_filename.push(".zst"); + } filenames.push(PathBuf::from(next_filename)); let count = filenames.len(); for i in (0..count-1).rev() { - rename(&filenames[i], &filenames[i+1])?; - } - - if self.compress { - for i in 2..count { - if filenames[i].extension().unwrap_or(std::ffi::OsStr::new("")) != "zst" { - let mut target = filenames[i].clone().into_os_string(); - target.push(".zst"); - Self::compress(&filenames[i], &target.into(), &options)?; - } + if self.compress + && filenames[i+0].extension().unwrap_or(std::ffi::OsStr::new("")) != "zst" + && filenames[i+1].extension().unwrap_or(std::ffi::OsStr::new("")) == "zst" + { + Self::compress(&filenames[i], &filenames[i+1], &options)?; + } else { + rename(&filenames[i], &filenames[i+1])?; } }