Skip to content

Commit

Permalink
Remove phase 1 and 2 uninstall receipts if they exist upon a successf…
Browse files Browse the repository at this point in the history
…ul install
  • Loading branch information
cole-h committed Nov 8, 2024
1 parent 6644b58 commit 95c9038
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/cli/subcommand/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use crate::{
cli::{
ensure_root,
interaction::{self, PromptChoice},
signal_channel, CommandExecute,
signal_channel,
subcommand::split_receipt::{PHASE1_RECEIPT_LOCATION, PHASE2_RECEIPT_LOCATION},
CommandExecute,
},
error::HasExpectedErrors,
plan::RECEIPT_LOCATION,
Expand Down Expand Up @@ -319,6 +321,20 @@ impl CommandExecute for Install {
copy_self_to_nix_dir()
.await
.wrap_err("Copying `nix-installer` to `/nix/nix-installer`")?;

if Path::new(PHASE1_RECEIPT_LOCATION).exists() {
tracing::debug!("Removing pre-existing uninstall phase 1 receipt at {PHASE1_RECEIPT_LOCATION} after successful install");
tokio::fs::remove_file(PHASE1_RECEIPT_LOCATION)
.await
.wrap_err_with(|| format!("Failed to remove uninstall phase 1 receipt at {PHASE1_RECEIPT_LOCATION}"))?;
}
if Path::new(PHASE2_RECEIPT_LOCATION).exists() {
tracing::debug!("Removing pre-existing uninstall phase 2 receipt at {PHASE2_RECEIPT_LOCATION} after successful install");
tokio::fs::remove_file(PHASE2_RECEIPT_LOCATION)
.await
.wrap_err_with(|| format!("Failed to remove uninstall phase 2 receipt at {PHASE2_RECEIPT_LOCATION}"))?;
}

println!(
"\
{success}\n\
Expand Down
4 changes: 2 additions & 2 deletions src/cli/subcommand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ mod split_receipt {

use crate::cli::CommandExecute;

const PHASE1_RECEIPT_LOCATION: &str = "/nix/uninstall-phase1.json";
const PHASE2_RECEIPT_LOCATION: &str = "/nix/uninstall-phase2.json";
pub(crate) const PHASE1_RECEIPT_LOCATION: &str = "/nix/uninstall-phase1.json";
pub(crate) const PHASE2_RECEIPT_LOCATION: &str = "/nix/uninstall-phase2.json";

/// Split an existing receipt into two phases, one that cleans up the Nix store (phase 2), and
/// one that does everything else (phase 1).
Expand Down

0 comments on commit 95c9038

Please sign in to comment.