aboutsummaryrefslogtreecommitdiff
path: root/src/activate.rs
diff options
context:
space:
mode:
authornotgne22020-10-01 20:24:09 -0700
committernotgne22020-10-01 20:24:09 -0700
commit05803e0ebaf417d9ba40645b6548a48bf51f9213 (patch)
tree17af19223dd8b207e328ae1732fe0bf3078df5f6 /src/activate.rs
parente14acaf2bdc14bbdc30f3d558b62f64fe33ff5f9 (diff)
Handle more command exits correctly
Diffstat (limited to '')
-rw-r--r--src/activate.rs39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/activate.rs b/src/activate.rs
index 3c7c16d..f75303f 100644
--- a/src/activate.rs
+++ b/src/activate.rs
@@ -87,22 +87,33 @@ pub async fn activate(
match activate_status {
Ok(s) if s.success() => (),
_ if auto_rollback => {
- Command::new("nix-env")
+ error!("Failed to execute activation command");
+
+ let nix_env_rollback_exit_status = Command::new("nix-env")
.arg("-p")
.arg(&profile_path)
.arg("--rollback")
.stdout(Stdio::null())
.stderr(Stdio::null())
- .spawn()?
+ .status()
.await?;
- let c = Command::new("nix-env")
+ if !nix_env_rollback_exit_status.success() {
+ good_panic!("`nix-env --rollback` failed");
+ }
+
+ let nix_env_list_generations_out = Command::new("nix-env")
.arg("-p")
.arg(&profile_path)
.arg("--list-generations")
.output()
.await?;
- let generations_list = String::from_utf8(c.stdout)?;
+
+ if !nix_env_list_generations_out.status.success() {
+ good_panic!("Listing `nix-env` generations failed");
+ }
+
+ let generations_list = String::from_utf8(nix_env_list_generations_out.stdout)?;
let last_generation_line = generations_list
.lines()
@@ -117,24 +128,32 @@ pub async fn activate(
debug!("Removing generation entry {}", last_generation_line);
warn!("Removing generation by ID {}", last_generation_id);
- Command::new("nix-env")
+ let nix_env_delete_generation_exit_status = Command::new("nix-env")
.arg("-p")
.arg(&profile_path)
.arg("--delete-generations")
.arg(last_generation_id)
.stdout(Stdio::null())
.stderr(Stdio::null())
- .spawn()?
+ .status()
.await?;
+ if !nix_env_delete_generation_exit_status.success() {
+ good_panic!("Failed to delete failed generation");
+ }
+
// TODO: Find some way to make sure this command never changes, otherwise this will not work
- Command::new("bash")
+ let re_activate_exit_status = Command::new("bash")
.arg("-c")
.arg(&activate_cmd)
- .spawn()?
+ .status()
.await?;
- good_panic!("Failed to execute activation command");
+ if !re_activate_exit_status.success() {
+ good_panic!("Failed to re-activate the last generation");
+ }
+
+ std::process::exit(1);
}
_ => {}
}
@@ -163,4 +182,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await?;
Ok(())
-} \ No newline at end of file
+}