Skip to content

Commit

Permalink
fixup: use wait_for_nix_store_dir() in CreateNixVolume
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-h committed Sep 6, 2024
1 parent 0afa743 commit a76908d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 57 deletions.
32 changes: 4 additions & 28 deletions src/action/macos/create_determinate_nix_volume.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
path::{Path, PathBuf},
time::Duration,
};
use std::path::{Path, PathBuf};

use tokio::process::Command;
use tracing::{span, Span};
Expand Down Expand Up @@ -183,30 +180,9 @@ impl Action for CreateDeterminateNixVolume {
.await
.map_err(Self::error)?;

let mut retry_tokens: usize = 50;
loop {
let mut command = Command::new("/usr/sbin/diskutil");
command.args(["info", "-plist"]);
command.arg(&self.name);
command.stderr(std::process::Stdio::null());
command.stdout(std::process::Stdio::null());
tracing::trace!(%retry_tokens, command = ?command.as_std(), "Checking for Nix Store volume existence");
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(100)).await;
}
crate::action::macos::wait_for_nix_store_dir()
.await
.map_err(Self::error)?;

self.create_fstab_entry
.try_execute()
Expand Down
31 changes: 2 additions & 29 deletions src/action/macos/create_nix_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ use crate::action::{
},
Action, ActionDescription, ActionError, ActionErrorKind, ActionTag, StatefulAction,
};
use std::{
path::{Path, PathBuf},
time::Duration,
};
use tokio::process::Command;
use std::path::{Path, PathBuf};
use tracing::{span, Span};

use super::{
Expand Down Expand Up @@ -179,30 +175,7 @@ impl Action for CreateNixVolume {
.await
.map_err(Self::error)?;

let mut retry_tokens: usize = 50;
loop {
let mut command = Command::new("/usr/sbin/diskutil");
command.args(["info", "-plist"]);
command.arg(&self.volume_label);
command.stderr(std::process::Stdio::null());
command.stdout(std::process::Stdio::null());
tracing::trace!(%retry_tokens, command = ?command.as_std(), "Checking for Nix Store volume existence");
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(100)).await;
}
super::wait_for_nix_store_dir().await.map_err(Self::error)?;

self.create_fstab_entry
.try_execute()
Expand Down

0 comments on commit a76908d

Please sign in to comment.