From ee5eb1af70e93af1891e97f6ee43ae78e54de9d1 Mon Sep 17 00:00:00 2001 From: afrojun <1935642+afrojun@users.noreply.github.com> Date: Thu, 5 Nov 2026 03:13:50 +0000 Subject: [PATCH] Check whether the DMG is still mounted instead of trusting detach A detach that reports "Resource busy" can still unmount the volume a moment later. Every retry after that failed with "No such file or directory", so the loop gave up and the forced detach failed the build, as it did on #22. Each retry now checks hdiutil info for the mount point and stops once it is gone, and the forced detach runs only if the volume is still mounted. The check captures hdiutil info before searching it, so pipefail cannot misread an early grep exit, and a failed query stops the script. Co-Authored-By: Claude Opus 5.5 --- package-dmg.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/package-dmg.sh b/package-dmg.sh index b027526..efcd53f 100755 --- a/package-dmg.sh +++ b/package-dmg.sh @@ -72,16 +72,21 @@ on run arguments end run APPLESCRIPT -# Finder can keep the volume busy for a moment after it lays out the window, so the detach is retried. -detached=false +# Finder can keep the volume busy for a moment after it lays out the window. A busy detach can still finish +# a moment later, so each retry checks whether the volume is still mounted rather than trusting the exit status. +is_mounted() { + local info + info="$(hdiutil info)" || { print -u2 "hdiutil info failed"; exit 1; } + [[ "$info" == *"$mount"* ]] +} for attempt in {1..10}; do - if hdiutil detach "$mount" >/dev/null 2>&1; then - detached=true - break - fi + hdiutil detach "$mount" >/dev/null 2>&1 || true + is_mounted || break sleep 1 done -[[ "$detached" == true ]] || hdiutil detach "$mount" -force >/dev/null +if is_mounted; then + hdiutil detach "$mount" -force >/dev/null +fi mounted=false hdiutil convert "$writable" \ -format UDZO \