feat: cleanup artifacts after installation

This commit is contained in:
Erica Marigold 2023-09-30 17:05:23 +05:30
parent c77d936c40
commit 5ba332acce
No known key found for this signature in database
GPG key ID: 7843994FD1386E35

View file

@ -1,4 +1,4 @@
use std::fs::File;
use std::fs::{read_dir, remove_dir_all, remove_file, DirEntry, File};
use actions_core as core;
use setup_lune::{
@ -33,4 +33,29 @@ fn main() {
meta,
)
.expect_or_log("failed to install lune. did we not have perms to write to the required directories?");
// Cleanup downloaded & unzipped stuff
let to_remove = read_dir(".")
.expect_or_log("failed to read current working directory")
.filter(|f| {
f.as_ref()
.expect_or_log("failed to read file of directory")
.file_name()
.to_string_lossy()
.starts_with("lune-")
})
.map(|elem| elem.unwrap())
.collect::<Vec<DirEntry>>();
for entry in to_remove {
let file_type = entry.file_type().expect_or_log("failed to get filetype for cleanup");
if file_type.is_file() {
remove_file(entry.path()).expect("failed to cleanup after installation!")
}
if file_type.is_dir() {
remove_dir_all(entry.path()).expect("failed to cleanup after installation!")
}
}
}