From e918f471cd36d80f3e1fedd9e1f4ebb5a432d8d9 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 26 Nov 2024 12:49:52 -0800 Subject: [PATCH] FetchAndUnpackNix: remove destination if it already exists --- src/action/base/fetch_and_unpack_nix.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/action/base/fetch_and_unpack_nix.rs b/src/action/base/fetch_and_unpack_nix.rs index e46d578f3..c3b9c6b21 100644 --- a/src/action/base/fetch_and_unpack_nix.rs +++ b/src/action/base/fetch_and_unpack_nix.rs @@ -8,6 +8,7 @@ use crate::{ action::{Action, ActionDescription, ActionError, ActionErrorKind, ActionTag, StatefulAction}, parse_ssl_cert, settings::UrlOrPath, + util::OnMissing, }; /** @@ -165,6 +166,15 @@ impl Action for FetchAndUnpackNix { // TODO(@Hoverbear): Pick directory tracing::trace!("Unpacking tar.xz"); + // NOTE(cole-h): If the destination exists (because maybe a previous install failed), we + // want to remove it so that tar doesn't complain with: + // trying to unpack outside of destination path: /nix/temp-install-dir + if self.dest.exists() { + crate::util::remove_dir_all(&self.dest, OnMissing::Ignore) + .await + .map_err(|e| Self::error(ActionErrorKind::Remove(self.dest.clone(), e)))?; + } + let decoder = xz2::read::XzDecoder::new(bytes.reader()); let mut archive = tar::Archive::new(decoder); archive.set_preserve_permissions(true);