Skip to content

Commit

Permalink
Graham/fh 463 determinatepkg failed to mount nix store (#1326)
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamc authored Nov 29, 2024
1 parent be8878d commit da73477
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/action/macos/create_determinate_nix_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,8 @@ impl Action for CreateDeterminateNixVolume {
"Not reverting encrypt_volume step (which would delete the disk encryption \
password) because deleting the volume failed"
);
} else {
if let Err(err) = self.encrypt_volume.try_revert().await {
errors.push(err);
}
} else if let Err(err) = self.encrypt_volume.try_revert().await {
errors.push(err);
}

// Purposefully not reversed
Expand Down
6 changes: 2 additions & 4 deletions src/action/macos/create_nix_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,8 @@ impl Action for CreateNixVolume {
"Not reverting encrypt_volume step (which would delete the disk encryption \
password) because deleting the volume failed"
);
} else {
if let Err(err) = encrypt_volume.try_revert().await {
errors.push(err);
}
} else if let Err(err) = encrypt_volume.try_revert().await {
errors.push(err);
}
}

Expand Down
35 changes: 28 additions & 7 deletions src/action/macos/encrypt_apfs_volume.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Duration;

use crate::{
action::{
macos::NIX_VOLUME_MOUNTD_DEST, Action, ActionDescription, ActionError, ActionErrorKind,
Expand Down Expand Up @@ -171,13 +173,32 @@ impl Action for EncryptApfsVolume {

let disk_str = &self.disk.to_str().expect("Could not turn disk into string"); /* Should not reasonably ever fail */

execute_command(
Command::new("/usr/sbin/diskutil")
.arg("mount")
.arg(&self.name),
)
.await
.map_err(Self::error)?;
let mut retry_tokens: usize = 10;
loop {
let mut command = Command::new("/usr/sbin/diskutil");
command.process_group(0);
command.args(["mount", &self.name]);
command.stdin(std::process::Stdio::null());
tracing::trace!(%retry_tokens, command = ?command.as_std(), "Waiting for volume mounting to succeed");

let output = command
.output()
.await
.map_err(|e| ActionErrorKind::command(&command, e))
.map_err(Self::error)?;

if output.status.success() {
break;
} else if retry_tokens == 0 {
return Err(Self::error(ActionErrorKind::command_output(
&command, output,
)))?;
} else {
retry_tokens = retry_tokens.saturating_sub(1);
}

tokio::time::sleep(Duration::from_millis(500)).await;
}

// Add the password to the user keychain so they can unlock it later.
let mut cmd = Command::new("/usr/bin/security");
Expand Down

0 comments on commit da73477

Please sign in to comment.