From bf6054c96dda08773b2056c8a7e6db684b159d86 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 19 Nov 2026 20:24:41 +0000 Subject: [PATCH] craft-update tests: retry hdiutil create and attach while the disk-image helper is busy --- crates/update/src/install.rs | 49 +++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/crates/update/src/install.rs b/crates/update/src/install.rs index 6cf91868a..690df3f38 100644 --- a/crates/update/src/install.rs +++ b/crates/update/src/install.rs @@ -4326,6 +4326,22 @@ exit 0 app } + /// Runs `hdiutil` with `args` (the caller holds its [`macos::disk_image_turn`]). The disk-image + /// helper can turn a request away with EAGAIN ("Resource temporarily unavailable") while it + /// is busy elsewhere, as on shared CI runners; that reply alone is retried, up to five + /// attempts over about eight seconds. Any other result returns at once. + fn hdiutil(args: &[&std::ffi::OsStr]) -> std::process::Output { + let mut output = std::process::Command::new("hdiutil").args(args).output().unwrap(); + for wait_ms in [500, 1000, 2000, 4000] { + if output.status.success() || !String::from_utf8_lossy(&output.stderr).contains("Resource temporarily unavailable") { + break; + } + std::thread::sleep(Duration::from_millis(wait_ms)); + output = std::process::Command::new("hdiutil").args(args).output().unwrap(); + } + output + } + /// A release-style disk image holding a `PhotoCraft.app` that reports `version`. The tests, /// in this process and in others, ask the disk-image helper one at a time; when a program /// that is not one of these tests keeps it busy, the test fails with what `hdiutil create` @@ -4335,12 +4351,17 @@ exit 0 bundle(&src, version); let dmg = dir.join(format!("photocraft-{version}-macos-universal.dmg")); let _one_at_a_time = macos::disk_image_turn(); - let output = std::process::Command::new("hdiutil") - .args(["create", "-quiet", "-format", "UDZO", "-volname", "PhotoCraft", "-srcfolder"]) - .arg(&src) - .arg(&dmg) - .output() - .unwrap(); + let output = hdiutil(&[ + "create".as_ref(), + "-quiet".as_ref(), + "-format".as_ref(), + "UDZO".as_ref(), + "-volname".as_ref(), + "PhotoCraft".as_ref(), + "-srcfolder".as_ref(), + src.as_os_str(), + dmg.as_os_str(), + ]); assert!(output.status.success(), "hdiutil create failed: {}", String::from_utf8_lossy(&output.stderr).trim()); dmg } @@ -4722,12 +4743,16 @@ exit 0 // One request at a time, as in `dmg`. let output = { let _one_at_a_time = macos::disk_image_turn(); - std::process::Command::new("hdiutil") - .args(["attach", "-nobrowse", "-readonly", "-noautoopen", "-noverify", "-mountpoint"]) - .arg(&mount) - .arg(&image) - .output() - .unwrap() + hdiutil(&[ + "attach".as_ref(), + "-nobrowse".as_ref(), + "-readonly".as_ref(), + "-noautoopen".as_ref(), + "-noverify".as_ref(), + "-mountpoint".as_ref(), + mount.as_os_str(), + image.as_os_str(), + ]) }; let _attached = Attached(mount.clone()); assert!(output.status.success(), "hdiutil attach failed: {}", String::from_utf8_lossy(&output.stderr).trim());