1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-04 17:44:11 +02:00

improve cleanup of leftover networks and workdirs

This commit is contained in:
Robin Appelman 2026-02-09 17:30:41 +01:00
commit 755573ba4b
2 changed files with 32 additions and 9 deletions

View file

@ -1,19 +1,21 @@
use bollard::Docker;
use crate::cloud::Cloud;
use bollard::network::CreateNetworkOptions;
use bollard::Docker;
use miette::{IntoDiagnostic, Result, WrapErr};
pub async fn clear_networks(docker: &Docker) -> Result<()> {
pub async fn clear_networks(docker: &Docker, instances: &[Cloud]) -> Result<()> {
let networks = docker
.list_networks::<&str>(None)
.await
.into_diagnostic()
.wrap_err("Failed to list docker networks")?;
for network in networks {
match network.name.as_deref() {
Some(name) if name.starts_with("haze-") => {
docker.remove_network(name).await.ok();
if let Some(name) = network.name.as_deref() {
if let Some(id) = name.strip_prefix("haze-") {
if !instances.iter().any(|cloud| cloud.id == id) {
docker.remove_network(name).await.ok();
}
}
_ => {}
}
}
Ok(())