From cb49f1cb404a193b66ac03a0334c3a5ab2e02b67 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Mon, 11 Dec 2023 15:09:18 +0100 Subject: [PATCH] Delete VNC socket file when deleting domain --- virtweb_backend/src/actors/libvirt_actor.rs | 9 +++++++++ virtweb_backend/src/app_config.rs | 5 +++++ virtweb_backend/src/libvirt_rest_structures.rs | 3 +-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/virtweb_backend/src/actors/libvirt_actor.rs b/virtweb_backend/src/actors/libvirt_actor.rs index 7b3895e..b06118d 100644 --- a/virtweb_backend/src/actors/libvirt_actor.rs +++ b/virtweb_backend/src/actors/libvirt_actor.rs @@ -165,6 +165,15 @@ impl Handler for LibVirtActor { ); let domain = Domain::lookup_by_uuid_string(&self.m, &msg.id.as_string())?; + let domain_name = domain.get_name()?; + + // Remove VNC socket + let vnc_socket = AppConfig::get().vnc_socket_for_domain(&domain_name); + if vnc_socket.exists() { + std::fs::remove_file(vnc_socket)?; + } + + // Delete the domain domain.undefine_flags(match msg.keep_files { true => sys::VIR_DOMAIN_UNDEFINE_KEEP_NVRAM, false => sys::VIR_DOMAIN_UNDEFINE_NVRAM, diff --git a/virtweb_backend/src/app_config.rs b/virtweb_backend/src/app_config.rs index 2c2218a..c639ff1 100644 --- a/virtweb_backend/src/app_config.rs +++ b/virtweb_backend/src/app_config.rs @@ -172,6 +172,11 @@ impl AppConfig { self.storage_path().join("vnc") } + /// Get VM vnc sockets path for domain + pub fn vnc_socket_for_domain(&self, name: &str) -> PathBuf { + self.vnc_sockets_path().join(format!("vnc-{}", name)) + } + /// Get VM vnc sockets directory pub fn disks_storage_path(&self) -> PathBuf { self.storage_path().join("disks") diff --git a/virtweb_backend/src/libvirt_rest_structures.rs b/virtweb_backend/src/libvirt_rest_structures.rs index 5c107d5..3677699 100644 --- a/virtweb_backend/src/libvirt_rest_structures.rs +++ b/virtweb_backend/src/libvirt_rest_structures.rs @@ -174,8 +174,7 @@ impl VMInfo { true => Some(GraphicsXML { r#type: "vnc".to_string(), socket: AppConfig::get() - .vnc_sockets_path() - .join(format!("vnc-{}", self.name)) + .vnc_socket_for_domain(&self.name) .to_string_lossy() .to_string(), }),