Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FetchAndUnpackNix: remove destination if it already exists #1319

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading