feat: periodic deletion of old archives
This commit is contained in:
parent
31fd0f0c51
commit
993ba2fe25
1 changed files with 26 additions and 0 deletions
|
@ -228,6 +228,32 @@ impl Federate for PccFederate {
|
|||
a.append_dir_all(".", self.get_content_path(false).await?)
|
||||
.unwrap();
|
||||
a.finish().unwrap();
|
||||
|
||||
let mut times: Vec<usize> = Vec::with_capacity(10);
|
||||
let mut dir = fs::read_dir(Path::new(&self.base_dir)).await?;
|
||||
while let Some(d) = dir.next_entry().await? {
|
||||
if d.path().is_dir() {
|
||||
continue;
|
||||
}
|
||||
let file = d.file_name().into_string().unwrap();
|
||||
if file.ends_with(".tar") {
|
||||
if let Some(time) = file.split(".tar").next() {
|
||||
times.push(time.parse::<usize>().unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
times.sort();
|
||||
|
||||
let mut times = times.iter().rev();
|
||||
for _ in 0..5 {
|
||||
times.next();
|
||||
}
|
||||
for t in times {
|
||||
let file = Path::new(&self.base_dir).join(format!("{t}.tar"));
|
||||
fs::remove_file(file).await?;
|
||||
}
|
||||
|
||||
Ok(path)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue