Skip to content

Commit

Permalink
ConfigureInitService: remove dest files on revert (if they exist) (#1266
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cole-h authored Oct 31, 2024
1 parent bbb9394 commit 7fcb69b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
14 changes: 0 additions & 14 deletions src/action/common/configure_determinate_nixd_init_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,6 @@ impl Action for ConfigureDeterminateNixdInitService {
async fn revert(&mut self) -> Result<(), ActionError> {
self.configure_init_service.try_revert().await?;

let file_to_remove = match self.init {
InitSystem::Launchd => Some(DARWIN_NIXD_DAEMON_DEST),
InitSystem::Systemd => Some(LINUX_NIXD_DAEMON_DEST),
InitSystem::None => None,
};

if let Some(file_to_remove) = file_to_remove {
tracing::trace!(path = %file_to_remove, "Removing");
tokio::fs::remove_file(file_to_remove)
.await
.map_err(|e| ActionErrorKind::Remove(file_to_remove.into(), e))
.map_err(Self::error)?;
}

Ok(())
}
}
Expand Down
36 changes: 24 additions & 12 deletions src/action/common/configure_init_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 7fcb69b

Please sign in to comment.