From b81a6a6c2843a4cf590bceafbad619519ea6adce Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 1 Sep 2023 17:55:51 +0300 Subject: fix: include filename in error message of being unable to rm image Sponsored-by: author --- src/libvirt.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libvirt.rs b/src/libvirt.rs index 403dc45..c262444 100644 --- a/src/libvirt.rs +++ b/src/libvirt.rs @@ -2,7 +2,7 @@ use crate::util::wait_for_ssh; use log::debug; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::thread; use std::time::Duration; use virt::connect::Connect; @@ -52,6 +52,10 @@ pub enum VirtError { #[error("couldn't set domain {0} to be autostarted")] Autostart(String, #[source] virt::error::Error), + /// Failed to delete image file. + #[error("failed to delete image file {0}")] + DeleteImage(PathBuf, #[source] std::io::Error), + /// Error doing I/O. #[error(transparent)] IoError(#[from] std::io::Error), @@ -175,7 +179,8 @@ impl Libvirt { .map_err(|err| VirtError::Undefine(name.to_string(), err))?; debug!("removing image file {}", image.display()); - std::fs::remove_file(image)?; + std::fs::remove_file(image) + .map_err(|e| VirtError::DeleteImage(image.to_path_buf(), e))?; } Ok(()) -- cgit v1.2.1