Skip to content

Commit

Permalink
FetchAndUnpackNix: remove destination if it already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-h committed Nov 26, 2024
1 parent 422a464 commit e918f47
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/action/base/fetch_and_unpack_nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
action::{Action, ActionDescription, ActionError, ActionErrorKind, ActionTag, StatefulAction},
parse_ssl_cert,
settings::UrlOrPath,
util::OnMissing,
};

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e918f47

Please sign in to comment.