summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFrerich Raabe <raabe@froglogic.com>2015-12-21 14:10:26 +0100
committerKatja Marttila <katja.marttila@theqtcompany.com>2016-01-13 07:36:06 +0000
commite53cb9d364f9809d24748039a0526d4ec57764d6 (patch)
tree0607a2b0f10ec2bcba4fe1e1411a0e29f9697095 /tools
parentba9ddaed740e3a6c1aa68018d316423974ef7258 (diff)
Let mkdmg.sh script on OS X actually create random temporary file names
When asking binarycreator to create an app bundle on OS X, temporary files are created in /tmp via, the name of which is determined via DMG=`mktemp "/tmp/$VOL.XXXXXX.dmg"` However, on OS X, this doesn't actually create a random file name. OS X uses the BSD implementation of 'mktemp'. The man page explains: The trailing `Xs' are replaced with the current process number and/or a unique letter combination. Note the *trailing*. Hence, on OS X, the 'XXXXXX' part should be at the end of the template. This manifested as a problem in case creation of the .dmg file is aborted (e.g. via Ctrl+C) in which case the temporary file is not removed. In that case, a subsequent attempt to create a .dmg will fail since mktemp fails to create the temporary file - since it's already there! The only remedy is to remove the temporary file by hand. Alas, 'hdiutil' and 'hdid' apparently depend on the file extension in order to detect the file format. So it's not just a matter of changing the template for mktemp. Instead, let's pass just '$VOL.XXXXXX' to mktemp but then tack on the file extension when using the file name. Change-Id: I7a1a548df24054e01630c441f259031045703ff3 Task-number: QTIFW-780 Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/binarycreator/resources/mkdmg.sh13
1 files changed, 7 insertions, 6 deletions
diff --git a/tools/binarycreator/resources/mkdmg.sh b/tools/binarycreator/resources/mkdmg.sh
index c651ec618..17c3d8d6b 100644
--- a/tools/binarycreator/resources/mkdmg.sh
+++ b/tools/binarycreator/resources/mkdmg.sh
@@ -52,14 +52,15 @@ VOL="$1"
FILES="$2"
PATHNAME=`dirname $FILES`
-DMG=`mktemp "/tmp/$VOL.XXXXXX.dmg"`
+# keep '.XXXXXX' at the end to satisfy 'mktemp' as shipped on OS X
+DMG=`mktemp "/tmp/$VOL.XXXXXX"`
# create temporary disk image and format, ejecting when done
SIZE=`du -sk ${FILES} | sed -n 's,^\([0-9]*\).*,\1,p'`
SIZE=$((${SIZE}/1000+1))
-hdiutil create "$DMG" -megabytes ${SIZE} -ov -volname "$VOL" -type UDIF -fs HFS+ >/dev/null
-DISK=`hdid "$DMG" | sed -ne 's,^\(.*\) *Apple_H.*,\1,p'`
-MOUNT=`hdid "$DMG" | sed -ne 's,^.*Apple_HFS[^/]*\(/.*\)$,\1,p'`
+hdiutil create "${DMG}.dmg" -megabytes ${SIZE} -ov -volname "$VOL" -type UDIF -fs HFS+ >/dev/null
+DISK=`hdid "${DMG}.dmg" | sed -ne 's,^\(.*\) *Apple_H.*,\1,p'`
+MOUNT=`hdid "${DMG}.dmg" | sed -ne 's,^.*Apple_HFS[^/]*\(/.*\)$,\1,p'`
# mount and copy files onto volume
cp -R "$PATHNAME/`basename $FILES`" "$MOUNT"
@@ -67,5 +68,5 @@ hdiutil eject $DISK >/dev/null
# convert to compressed image, delete temp image
rm -f "$PATHNAME/${VOL}.dmg"
-hdiutil convert "$DMG" -format UDZO -o "$PATHNAME/${VOL}.dmg" >/dev/null
-rm -f "$DMG"
+hdiutil convert "${DMG}.dmg" -format UDZO -o "$PATHNAME/${VOL}.dmg" >/dev/null
+rm -f "${DMG}.dmg"