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 <t.lamprecht@proxmox.com>
This commit is contained in:
parent
1dc2fe20dd
commit
3aade17125
@ -95,22 +95,22 @@ 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() {
|
||||
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])?;
|
||||
}
|
||||
|
||||
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 let Some(max_files) = max_files {
|
||||
|
Loading…
Reference in New Issue
Block a user