diff --git a/federate/publiccodeyml/src/lib.rs b/federate/publiccodeyml/src/lib.rs index c145898..1142b9f 100644 --- a/federate/publiccodeyml/src/lib.rs +++ b/federate/publiccodeyml/src/lib.rs @@ -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 = 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::().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) } }