From 5ba332acceeceda6e19ee99fbfad655946197156 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Sat, 30 Sep 2023 17:05:23 +0530 Subject: [PATCH] feat: cleanup artifacts after installation --- package/action/src/main.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/package/action/src/main.rs b/package/action/src/main.rs index 286a5c0..b1039f9 100644 --- a/package/action/src/main.rs +++ b/package/action/src/main.rs @@ -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::>(); + + 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!") + } + } }