Skip to content

Commit

Permalink
FetchAndUnpackNix: remove destination if it already exists (#1319)
Browse files Browse the repository at this point in the history
* fixup: unnnecessary clone

* FetchAndUnpackNix: remove destination if it already exists
  • Loading branch information
cole-h authored Nov 26, 2024
1 parent 10e6075 commit e887cc3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 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 @@ -164,15 +165,23 @@ impl Action for FetchAndUnpackNix {

// TODO(@Hoverbear): Pick directory
tracing::trace!("Unpacking tar.xz");
let dest_clone = self.dest.clone();

// 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);
archive.set_preserve_mtime(true);
archive.set_unpack_xattrs(true);
archive
.unpack(&dest_clone)
.unpack(&self.dest)
.map_err(FetchUrlError::Unarchive)
.map_err(Self::error)?;

Expand Down

0 comments on commit e887cc3

Please sign in to comment.