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);