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(), }),