From 4a007cea78ccc8c0eece7d53f5a0973fbb7125f3 Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Wed, 11 May 2022 12:03:59 -0600 Subject: [PATCH] cleanup assets and scripts on uninstall --- backend/src/install/cleanup.rs | 45 +++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/backend/src/install/cleanup.rs b/backend/src/install/cleanup.rs index 5635dcfd4..f5a0d5da2 100644 --- a/backend/src/install/cleanup.rs +++ b/backend/src/install/cleanup.rs @@ -6,19 +6,20 @@ use sqlx::{Executor, Sqlite}; use tracing::instrument; use super::{PKG_ARCHIVE_DIR, PKG_DOCKER_DIR}; -use crate::db::model::{InstalledPackageDataEntry, PackageDataEntry}; -use crate::{config::not_found, dependencies::reconfigure_dependents_with_live_pointers}; -use crate::{config::ConfigReceipts, context::RpcContext}; -use crate::{ - db::model::AllPackageData, - s9pk::manifest::{Manifest, PackageId}, +use crate::config::{not_found, ConfigReceipts}; +use crate::context::RpcContext; +use crate::db::model::{ + AllPackageData, CurrentDependencyInfo, CurrentDependencyInfo, InstalledPackageDataEntry, + InstalledPackageDataEntry, PackageDataEntry, PackageDataEntry, }; -use crate::{db::model::CurrentDependencyInfo, error::ErrorCollection}; -use crate::{ - dependencies::DependencyErrors, - util::{Apply, Version}, +use crate::dependencies::{ + reconfigure_dependents_with_live_pointers, DependencyErrors, TryHealReceipts, }; -use crate::{dependencies::TryHealReceipts, Error}; +use crate::error::ErrorCollection; +use crate::s9pk::manifest::{Manifest, PackageId, PackageId}; +use crate::util::{Apply, Version, Version}; +use crate::volume::PKG_VOLUME_DIR; +use crate::Error; pub struct UpdateDependencyReceipts { try_heal: TryHealReceipts, @@ -148,6 +149,28 @@ pub async fn cleanup(ctx: &RpcContext, id: &PackageId, version: &Version) -> Res .await .apply(|res| errors.handle(res)); } + let assets_path = ctx + .datadir + .join(PKG_VOLUME_DIR) + .join(id) + .join("assets") + .join(version.as_str()); + if tokio::fs::metadata(&assets_path).await.is_ok() { + tokio::fs::remove_dir_all(&assets_path) + .await + .apply(|res| errors.handle(res)); + } + let scripts_path = ctx + .datadir + .join(PKG_VOLUME_DIR) + .join(id) + .join("scripts") + .join(version.as_str()); + if tokio::fs::metadata(&scripts_path).await.is_ok() { + tokio::fs::remove_dir_all(&scripts_path) + .await + .apply(|res| errors.handle(res)); + } errors.into_result() }