appmgr: handle optional dep unmounts on uninstall

This commit is contained in:
Aiden McClelland
2021-03-15 16:21:14 -06:00
committed by Keagan McClelland
parent 7bdc109bd4
commit 43e89df652

View File

@@ -60,24 +60,20 @@ pub async fn remove(
log::info!("Destroying mounted volume."); log::info!("Destroying mounted volume.");
log::info!("Unbinding shared filesystem."); log::info!("Unbinding shared filesystem.");
for (dep, info) in manifest.dependencies.0.iter() { for (dep, info) in manifest.dependencies.0.iter() {
if info.mount_public { if crate::apps::list_info().await?.contains_key(dep) {
crate::disks::unmount( let dep_man = crate::apps::manifest(dep).await?;
Path::new(crate::VOLUMES) if info.mount_public && dep_man.public.is_some() {
let path = Path::new(crate::VOLUMES)
.join(name) .join(name)
.join("start9") .join("start9")
.join("public") .join("public")
.join(&dep), .join(&dep);
) if path.exists() {
.await?; crate::disks::unmount(&path).await?;
}
} }
if info.mount_shared { if info.mount_shared {
if let Some(shared) = match crate::apps::manifest(dep).await { if let Some(shared) = dep_man.shared {
Ok(man) => man.shared,
Err(e) => {
log::error!("Failed to Fetch Dependency Manifest: {}", e);
None
}
} {
let path = Path::new(crate::VOLUMES) let path = Path::new(crate::VOLUMES)
.join(name) .join(name)
.join("start9") .join("start9")
@@ -96,6 +92,38 @@ pub async fn remove(
} }
} }
} }
}
if manifest.public.is_some() || manifest.shared.is_some() {
for dependent in crate::apps::dependents(&manifest.id, false).await? {
if let Some(info) = crate::apps::manifest(&dependent)
.await?
.dependencies
.0
.get(&manifest.id)
{
if info.mount_public && manifest.public.is_some() {
let path = Path::new(crate::VOLUMES)
.join(name)
.join("start9")
.join("public")
.join(&manifest.id);
if path.exists() {
crate::disks::unmount(&path).await?;
}
}
if info.mount_shared && manifest.shared.is_some() {
let path = Path::new(crate::VOLUMES)
.join(name)
.join("start9")
.join("shared")
.join(&manifest.id);
if path.exists() {
crate::disks::unmount(&path).await?;
}
}
}
}
}
tokio::fs::remove_dir_all(Path::new(crate::VOLUMES).join(name)).await?; tokio::fs::remove_dir_all(Path::new(crate::VOLUMES).join(name)).await?;
log::info!("Pruning unused docker images."); log::info!("Pruning unused docker images.");
crate::ensure_code!( crate::ensure_code!(