From b920b384d3c1a63fb894571e5434757eb79f4a83 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Tue, 25 Oct 2022 09:06:04 -0700 Subject: [PATCH] No long sleep, busy poll instead --- src/actions/meta/darwin/create_apfs_volume.rs | 46 +++++++++++++++---- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/src/actions/meta/darwin/create_apfs_volume.rs b/src/actions/meta/darwin/create_apfs_volume.rs index 04ddd70..4f42fdf 100644 --- a/src/actions/meta/darwin/create_apfs_volume.rs +++ b/src/actions/meta/darwin/create_apfs_volume.rs @@ -3,16 +3,21 @@ use std::{ path::{Path, PathBuf}, time::Duration, }; +use tokio::process::Command; -use crate::actions::base::{ - darwin::{ - BootstrapVolume, BootstrapVolumeError, CreateSyntheticObjects, CreateSyntheticObjectsError, - CreateVolume, CreateVolumeError, EnableOwnership, EnableOwnershipError, EncryptVolume, - EncryptVolumeError, UnmountVolume, UnmountVolumeError, - }, - CreateFile, CreateFileError, CreateOrAppendFile, CreateOrAppendFileError, -}; use crate::actions::{base::darwin, Action, ActionDescription, ActionState, Actionable}; +use crate::{ + actions::base::{ + darwin::{ + BootstrapVolume, BootstrapVolumeError, CreateSyntheticObjects, + CreateSyntheticObjectsError, CreateVolume, CreateVolumeError, EnableOwnership, + EnableOwnershipError, EncryptVolume, EncryptVolumeError, UnmountVolume, + UnmountVolumeError, + }, + CreateFile, CreateFileError, CreateOrAppendFile, CreateOrAppendFileError, + }, + execute_command, +}; const NIX_VOLUME_MOUNTD_DEST: &str = "/Library/LaunchDaemons/org.nixos.darwin-store.plist"; @@ -197,8 +202,23 @@ impl Actionable for CreateApfsVolume { bootstrap_volume.execute().await?; - // TODO: Check wait - tokio::time::sleep(Duration::from_millis(5000)).await; + let mut retry_tokens: usize = 50; + loop { + tracing::trace!(%retry_tokens, "Checking for Nix Store existence"); + let status = Command::new("/usr/sbin/diskutil") + .args(["info", "/nix"]) + .stderr(std::process::Stdio::null()) + .stdout(std::process::Stdio::null()) + .status() + .await + .map_err(Self::Error::Command)?; + if status.success() || retry_tokens == 0 { + break; + } else { + retry_tokens = retry_tokens.saturating_sub(1); + } + tokio::time::sleep(Duration::from_millis(100)).await; + } enable_ownership.execute().await?; @@ -295,4 +315,10 @@ pub enum CreateApfsVolumeError { DarwinUnmountVolume(#[from] UnmountVolumeError), #[error(transparent)] CreateOrAppendFile(#[from] CreateOrAppendFileError), + #[error("Failed to execute command")] + Command( + #[source] + #[serde(serialize_with = "crate::serialize_error_to_display")] + std::io::Error, + ), }