aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2023-07-24 18:13:44 +0200
committer0neGal <mail@0negal.com>2023-07-24 18:13:44 +0200
commita01a44e75837a54b4bd9c3ba0a8171364c0d654d (patch)
treeccc40988d16d3d142d771ff9ce8cc2dc226bfd81
parent9d33c21f489c2d3d3e4bfd4fc0cf4ff3d613b9fd (diff)
downloadViper-a01a44e75837a54b4bd9c3ba0a8171364c0d654d.tar.gz
Viper-a01a44e75837a54b4bd9c3ba0a8171364c0d654d.zip
cleanup leftover files when installing packages
-rw-r--r--src/modules/packages.js25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/modules/packages.js b/src/modules/packages.js
index 27df20a..a20cb5a 100644
--- a/src/modules/packages.js
+++ b/src/modules/packages.js
@@ -165,6 +165,22 @@ packages.install = async (url, author, package_name, version) => {
let name = packages.format_name(author, package_name, version);
+ // removes zip's and folders
+ let cleanup = () => {
+ console.info("Cleaning up cache folder of mod:", name);
+ if (zip_path && fs.existsSync(zip_path)) {
+ fs.rm(zip_path, {recursive: true});
+ console.ok("Cleaned archive of mod:", name);
+ }
+
+ if (package_path && fs.existsSync(package_path)) {
+ fs.rm(zip_path, {recursive: true});
+ console.ok("Cleaned mod folder:", name);
+ }
+
+ console.ok("Cleaned up cache folder of mod:", name);
+ }
+
console.info("Downloading package:", name);
// download `url` to a temporary dir, and return the path to it
let zip_path = await packages.download(url, name);
@@ -199,10 +215,12 @@ packages.install = async (url, author, package_name, version) => {
ipcMain.emit("failed-mod", name);
// other unhandled error
- return console.error(
+ console.error(
"Verification of package failed:", name,
", reason:", verification
);
+
+ return cleanup();
}
console.ok("Verified package:", name);
@@ -230,6 +248,9 @@ packages.install = async (url, author, package_name, version) => {
if (! moved) {
ipcMain.emit("failed-mod", name);
console.error("Moving package failed:", name);
+
+ cleanup();
+
return false;
}
@@ -239,6 +260,8 @@ packages.install = async (url, author, package_name, version) => {
})
console.ok("Installed package:", name);
+ cleanup();
+
return true;
}