Skip to content

Commit f3cea9f

Browse files
committed
fix(packaging/macos): detach DMG by attach mount point, not volname
- Capture device and mount point directly from `hdiutil attach` output instead of using hardcoded volume name, preventing conflicts when another volume already uses the volname - When a volume name collision occurs, macOS mounts the DMG at an alternate path (e.g. "/Volumes/Stitch 1"), but Finder "disk" reference and hardcoded paths would target the wrong volume - Update Finder layout and eject commands to use the actual mount folder name (`basename "$MNT"`) instead of the requested volname - Pass captured mount point to `is_detached()` and `detach_dmg()` functions to validate against the correct path - Add validation that device, mount point, and directory all exist after attach, with detailed error output if attach fails - Update error messages and comments to reference actual mount path instead of hardcoded "/Volumes/$VOL"
1 parent 18a075d commit f3cea9f

5 files changed

Lines changed: 35 additions & 18 deletions

File tree

.textile-monorepo-source

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b54c9b593d670eecd0d979dc1d8d75c81acda182
1+
e79e08b5a7cbf446fb15f9fb08dfa72fb86749df

.textile-stitch-release-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.132
1+
0.1.133

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stitch-bot"
3-
version = "0.1.132"
3+
version = "0.1.133"
44
edition = "2021"
55
description = "Stitch — Textile filler-network operator bot; market-makes the filler order book with signed UniswapX limit orders."
66
license = "AGPL-3.0-or-later"

packaging/macos/make-dmg.sh

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,22 @@ SIZE_MB=$(( $(du -sm "$STAGE" | cut -f1) + 50 ))
4949
hdiutil create -srcfolder "$STAGE" -volname "$VOL" -fs HFS+ \
5050
-format UDRW -size "${SIZE_MB}m" -ov "$TMP_DMG" >/dev/null
5151

52-
DEV="$(hdiutil attach -readwrite -noverify -noautoopen "$TMP_DMG" \
53-
| awk '/Apple_HFS/ {print $1; exit}')"
52+
# Capture device + mount point from this attach. If another volume already uses
53+
# the volname, macOS mounts us at "/Volumes/Stitch 1" (etc.); Finder "disk Stitch"
54+
# and a hardcoded /Volumes/$VOL path would then target the wrong volume.
55+
ATTACH_OUT="$(hdiutil attach -readwrite -noverify -noautoopen "$TMP_DMG")"
56+
DEV="$(printf '%s\n' "$ATTACH_OUT" | awk '/Apple_HFS/ {print $1; exit}')"
57+
# Mount path is everything from /Volumes/… (may contain spaces).
58+
MNT="$(printf '%s\n' "$ATTACH_OUT" | awk '/Apple_HFS/ {
59+
match($0, /\/Volumes\/.*/); if (RSTART) print substr($0, RSTART, RLENGTH); exit
60+
}')"
61+
[ -n "$DEV" ] && [ -n "$MNT" ] && [ -d "$MNT" ] || {
62+
echo "error: failed to attach $TMP_DMG (dev='$DEV' mnt='$MNT')" >&2
63+
printf '%s\n' "$ATTACH_OUT" >&2
64+
exit 1
65+
}
66+
# Finder disk name matches the mount folder (e.g. "Stitch" or "Stitch 1").
67+
DISK_NAME="$(basename "$MNT")"
5468
# Let the volume settle before scripting Finder.
5569
sleep 2
5670

@@ -59,7 +73,7 @@ sleep 2
5973
# still works — it just lacks the custom positions/arrow.
6074
osascript <<OSA || echo "warning: Finder layout failed; shipping a plain drag-to-Applications image" >&2
6175
tell application "Finder"
62-
tell disk "$VOL"
76+
tell disk "$DISK_NAME"
6377
open
6478
set current view of container window to icon view
6579
set toolbar visible of container window to false
@@ -85,31 +99,34 @@ sync
8599
# Finder often keeps the volume busy for a few seconds after layout (Spotlight /
86100
# .DS_Store / the container window). A single detach or even -force can fail with
87101
# "Resource busy" (hdiutil exit 16) on CI runners. Close the window, ask Finder to
88-
# eject, then retry detach with backoff before converting.
102+
# eject *this* mount, then retry detach with backoff before converting.
89103
is_detached() {
90104
local target="$1"
105+
local mount="$2"
91106
# Mount point gone and device no longer listed → already ejected (e.g. via Finder).
92-
if [ ! -d "/Volumes/$VOL" ] && ! hdiutil info 2>/dev/null | grep -q "$target"; then
107+
if [ ! -d "$mount" ] && ! hdiutil info 2>/dev/null | grep -Fq "$target"; then
93108
return 0
94109
fi
95110
return 1
96111
}
97112

98113
detach_dmg() {
99114
local target="$1"
115+
local mount="$2"
116+
local disk_name="$3"
100117
local attempt
101-
# Best-effort: drop Finder's hold before hdiutil fights it.
118+
# Best-effort: drop Finder's hold on this mount before hdiutil fights it.
102119
osascript <<OSA >/dev/null 2>&1 || true
103120
tell application "Finder"
104121
try
105-
close every window of disk "$VOL"
122+
close every window of disk "$disk_name"
106123
end try
107124
try
108-
eject disk "$VOL"
125+
eject disk "$disk_name"
109126
end try
110127
end tell
111128
OSA
112-
if is_detached "$target"; then
129+
if is_detached "$target" "$mount"; then
113130
return 0
114131
fi
115132
for attempt in 1 2 3 4 5 6 7 8; do
@@ -119,21 +136,21 @@ OSA
119136
if hdiutil detach "$target" -force >/dev/null 2>&1; then
120137
return 0
121138
fi
122-
# Also try the mount point — device node vs path can disagree after eject.
123-
if [ -d "/Volumes/$VOL" ] && hdiutil detach "/Volumes/$VOL" -force >/dev/null 2>&1; then
139+
# Device node vs path can disagree after a partial eject — only this mount.
140+
if [ -d "$mount" ] && hdiutil detach "$mount" -force >/dev/null 2>&1; then
124141
return 0
125142
fi
126-
if is_detached "$target"; then
143+
if is_detached "$target" "$mount"; then
127144
return 0
128145
fi
129146
sleep "$attempt"
130147
done
131-
echo "error: could not detach $target (/Volumes/$VOL) after retries" >&2
148+
echo "error: could not detach $target ($mount) after retries" >&2
132149
hdiutil info >&2 || true
133150
return 1
134151
}
135152

136-
detach_dmg "$DEV"
153+
detach_dmg "$DEV" "$MNT" "$DISK_NAME"
137154
hdiutil convert "$TMP_DMG" -format UDZO -imagekey zlib-level=9 -o "$DMG" >/dev/null
138155

139156
# Ad-hoc ("-") DMGs aren't worth signing (nothing verifies them); sign only with

0 commit comments

Comments
 (0)