From e13043ad4d0d34a17b94b56849e2e63bbc87f7bc Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Thu, 31 Oct 2024 08:37:50 -0700 Subject: [PATCH] ConfigureInitService: remove dest files on revert (if they exist) --- src/action/common/configure_init_service.rs | 36 ++++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/action/common/configure_init_service.rs b/src/action/common/configure_init_service.rs index 2714b0d7..cd9871d7 100644 --- a/src/action/common/configure_init_service.rs +++ b/src/action/common/configure_init_service.rs @@ -610,18 +610,6 @@ impl Action for ConfigureInitService { errors.push(err); } - for socket in self.socket_files.iter() { - if socket.dest.exists() { - tracing::trace!(path = %socket.dest.display(), "Removing"); - if let Err(err) = tokio::fs::remove_file(&socket.dest) - .await - .map_err(|e| ActionErrorKind::Remove(socket.dest.to_path_buf(), e)) - { - errors.push(err); - } - } - } - if Path::new(TMPFILES_DEST).exists() { if let Err(err) = tokio::fs::remove_file(TMPFILES_DEST) .await @@ -647,6 +635,30 @@ impl Action for ConfigureInitService { }, }; + if let Some(dest) = &self.service_dest { + if dest.exists() { + tracing::trace!(path = %dest.display(), "Removing"); + if let Err(err) = tokio::fs::remove_file(dest) + .await + .map_err(|e| ActionErrorKind::Remove(PathBuf::from(dest), e)) + { + errors.push(err); + } + } + } + + for socket in self.socket_files.iter() { + if socket.dest.exists() { + tracing::trace!(path = %socket.dest.display(), "Removing"); + if let Err(err) = tokio::fs::remove_file(&socket.dest) + .await + .map_err(|e| ActionErrorKind::Remove(socket.dest.to_path_buf(), e)) + { + errors.push(err); + } + } + } + if errors.is_empty() { Ok(()) } else if errors.len() == 1 {