]> gitweb.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
package: detach stale WinUAE DMG mounts
authorStefan Reinauer <stefan.reinauer@coreboot.org>
Sun, 21 Jun 2026 18:35:56 +0000 (11:35 -0700)
committerStefan Reinauer <stefan.reinauer@coreboot.org>
Tue, 7 Jul 2026 21:00:11 +0000 (14:00 -0700)
A previous failed or interrupted packaging run can leave /Volumes/WinUAE

mounted and make the next hdiutil attach pick a different mount point.

Detect that case, detach the old image mount, and fail if the path

belongs to something other than a disk image.

tools/macos-dmg.sh

index d22c41ed3ffe05e121ed33b976ef78f58b86449e..ab0f4e74d77d69a1929fb7ef19f23291e7cd46da 100755 (executable)
@@ -90,6 +90,32 @@ apply_volume_icon() {
 
 apply_volume_icon "${staging_dir}"
 
+detach_existing_volume_mount() {
+    local target_mount="/Volumes/${volume_name}"
+
+    if [[ ! -e "${target_mount}" ]]; then
+        return
+    fi
+
+    if ! hdiutil info | awk -F '\t' -v target="${target_mount}" '$NF == target { found = 1 } END { exit found ? 0 : 1 }'; then
+        echo "error: ${target_mount} already exists and is not a mounted disk image" >&2
+        echo "error: detach or rename it before creating the WinUAE DMG" >&2
+        exit 1
+    fi
+
+    echo "detaching existing ${target_mount} before creating the WinUAE DMG"
+    hdiutil detach "${target_mount}" -quiet
+    for _ in {1..20}; do
+        if [[ ! -e "${target_mount}" ]]; then
+            return
+        fi
+        sleep 0.5
+    done
+
+    echo "error: ${target_mount} is still present after detach" >&2
+    exit 1
+}
+
 background_tiff="${staging_dir}/.background/background.tiff"
 background_source="${source_dir}/od-unix/graphics/dmg_background.tiff"
 if [[ ! -f "${background_source}" ]]; then
@@ -98,6 +124,7 @@ if [[ ! -f "${background_source}" ]]; then
 fi
 cp "${background_source}" "${background_tiff}"
 
+detach_existing_volume_mount
 hdiutil create -volname "${volume_name}" -srcfolder "${staging_dir}" -fs HFS+ -format UDRW -ov "${rw_dmg}" >/dev/null
 mount_dir="$(hdiutil attach "${rw_dmg}" -readwrite -noverify -noautoopen | awk -F '\t' '/\/Volumes\// { print $NF; exit }')"
 if [[ -z "${mount_dir}" || ! -d "${mount_dir}" ]]; then