feat: periodic deletion of old archives

This commit is contained in:
Aravinth Manivannan 2022-07-15 20:12:15 +05:30
parent 31fd0f0c51
commit 993ba2fe25
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88

View file

@ -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)
}
}