Skip to content

Commit

Permalink
Remove executables older than 30 days
Browse files Browse the repository at this point in the history
  • Loading branch information
marlonbaeten committed Feb 3, 2025
1 parent fe94f52 commit 777ba2d
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,35 @@ pub async fn remove_unused_executables(state: AppState) -> anyhow::Result<()> {
let executables = get_executables().await;
let commit_hashes = state.github.get_commit_hashes();

// check if any of the executables are not in the commit hashes
for executable in executables {
if !commit_hashes
.iter()
.any(|hash| hash == executable.hash() || hash == executable.trigger_hash())
{
info!("Removing unused executable: {:?}", executable.path());
// tokio::fs::remove_file(executable.path()).await?;
} else {
info!("Keeping executable: {:?}", executable.path());
// remove old executables (after 30 days)
if let Ok(metadata) = tokio::fs::metadata(executable.path()).await {
let Ok(created) = metadata.created() else {
continue;
};

let Ok(duration) = created.elapsed() else {
continue;
};

if duration.as_secs() > 30 * 24 * 60 * 60 {
tokio::fs::remove_file(executable.path()).await?;
info!("Removing old executable: {:?}", executable.path());
} else {
info!(
"Keeping recent executable: {:?} {} days",
executable.path(),
duration.as_secs() / (24 * 60 * 60)
);
}
} else {
info!("Keeping used executable: {:?}", executable.path());
}
}
}

Expand Down

0 comments on commit 777ba2d

Please sign in to comment.