Sunday, June 20, 2010

Bug with hdiutil and symlinks

I got an error report from an InstaDMG user who was using symlinks to point at their installer DVD. I had never tried out using symlinks for that, and so tried it out, successfully, and wrote back saying that it was working for me (with a much newer version of InstaDMG), and that they should probably be using the -I flag to specify the disk rather than use a symlink. But I did do some more testing while I was setup this way, and ran into a problem just once after a couple of runs of InstaDMG.

It turns out that there is a bug in hdiutil, at least on 10.6.4, when it comes to resolving symlinks. But this bug only seems to come out on some percentage of runs, and even then the percentage seems to vary with the hardware (or some other variable). On my iMac8,1 I see it 15-25% of the time, while with my iMac5,1 I only see it 0.5% of the time. Granted the older iMac is running a brand-new install, where the newer iMac is running an OS that I constantly beat on.

I have reported this back to Apple as Radar number 8111753, as well as on OpenRadar. But I am curious if other people are getting error numbers like I am, so if you would like to run the following script a few times on your system and post the results in the comments that would be great.

#!/bin/bash

# print the system information
/usr/sbin/system_profiler SPHardwareDataType SPSoftwareDataType | /usr/bin/awk '/Model Identifier:|System Version:/ { $1 = ""; $2 = ""; gsub(/^[ \t]+|[ \t]+$/,""); print }'

# create a temproary folder with three items in it
TEMP_FOLDER=`/usr/bin/mktemp -d /tmp/hdiutilBugTest.XXXX`
/usr/bin/touch "$TEMP_FOLDER/a"
/usr/bin/touch "$TEMP_FOLDER/b"
/usr/bin/touch "$TEMP_FOLDER/c"

# create a compressed image from the temp folder
/usr/bin/hdiutil create -srcfolder "$TEMP_FOLDER" "$TEMP_FOLDER/testImage.dmg" 1>/dev/null

# create the symlink to the image
/bin/ln -s "testImage.dmg" "$TEMP_FOLDER/symlink"

SYMLINK_PATH="$TEMP_FOLDER/symlink"
ABSOLUTE_PATH="$TEMP_FOLDER/testImage.dmg"

PATHS[0]="$SYMLINK_PATH"
PATHS[1]="$ABSOLUTE_PATH"

REPEAT_COUNT=1000
IFS=$'\n'
for THIS_PATH in ${PATHS[@]}; do
 echo "Working on: $THIS_PATH"
 FAILED_COUNT=0
 i=0
 while [ $i -lt $REPEAT_COUNT ]; do
  /usr/bin/hdiutil imageinfo "$THIS_PATH" 1>/dev/null 2>/dev/null
  if [ $? -ne 0 ]; then
   let FAILED_COUNT=FAILED_COUNT+1
  fi
  let i=i+1
 done
 echo "  Failed $FAILED_COUNT out of $REPEAT_COUNT times"
done

# delete the temp folder
if [ ! -z "$TEMP_FOLDER" ] && [ -d "$TEMP_FOLDER" ]; then
 /bin/rm -rf "$TEMP_FOLDER"
fi

13 comments:

  1. Macmini3,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.95PK/symlink
    Failed 43 out of 1000 times
    Working on: /tmp/hdiutilBugTest.95PK/testImage.dmg
    Failed 0 out of 1000 times


    I ran it a few more times, had failures on the symlink between 43 and 24 times, no failures on the dmg.

    ReplyDelete
  2. First run:
    MacBookPro5,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.WNvK/symlink
    Failed 12 out of 1000 times
    Working on: /tmp/hdiutilBugTest.WNvK/testImage.dmg
    Failed 0 out of 1000 times

    Second run:
    Working on: /tmp/hdiutilBugTest.7nKq/symlink
    Failed 9 out of 1000 times
    Working on: /tmp/hdiutilBugTest.7nKq/testImage.dmg
    Failed 0 out of 1000 times

    Third run:
    Working on: /tmp/hdiutilBugTest.XmDM/symlink
    Failed 14 out of 1000 times
    Working on: /tmp/hdiutilBugTest.XmDM/testImage.dmg
    Failed 0 out of 1000 times

    ReplyDelete
  3. MacBookPro5,4
    Mac OS X 10.6.3 (10D573)
    Working on: /tmp/hdiutilBugTest.he6s/symlink
    Failed 15 out of 1000 times
    Working on: /tmp/hdiutilBugTest.he6s/testImage.dmg
    Failed 0 out of 1000 times

    ReplyDelete
  4. MacBookPro5,4
    Mac OS X 10.5.8 (9L31a)
    Working on: /tmp/hdiutilBugTest.W7W7/symlink
    Failed 0 out of 1000 times
    Working on: /tmp/hdiutilBugTest.W7W7/testImage.dmg
    Failed 0 out of 1000 times

    ReplyDelete
  5. First Run:
    MacBookPro5,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.CfbQ/symlink
    Failed 3 out of 1000 times
    Working on: /tmp/hdiutilBugTest.CfbQ/testImage.dmg
    Failed 0 out of 1000 times

    Second run:
    MacBookPro5,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.lSaz/symlink
    Failed 15 out of 1000 times
    Working on: /tmp/hdiutilBugTest.lSaz/testImage.dmg
    Failed 0 out of 1000 times

    Third run:
    MacBookPro5,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.FoHw/symlink
    Failed 13 out of 1000 times
    Working on: /tmp/hdiutilBugTest.FoHw/testImage.dmg
    Failed 0 out of 1000 times

    ReplyDelete
  6. Hey Karl, like everybody else I'm getting no errors on the DMG portion.

    on my MacBookAir2,1 running Mac OS X 10.6.4 (10F569):
    1st run 21 failures, 2nd 24, third 11

    on my MacBookPro5,1 running Mac OS X 10.6.3 (10D573)
    1st run 36 failures, 2nd 19, third 28

    if you want to collect the data comprehensively, google docs&spreadsheets can do easy form generation and output the data in csv....

    ReplyDelete
  7. MacBookPro2,2
    Mac OS X 10.6.3 (10D573)
    Working on: /tmp/hdiutilBugTest.h3cE/symlink
    Failed 60 out of 1000 times
    Working on: /tmp/hdiutilBugTest.h3cE/testImage.dmg
    Failed 0 out of 1000 times
    SEJJ:~ sejj$ ./karltest.sh
    MacBookPro2,2
    Mac OS X 10.6.3 (10D573)
    Working on: /tmp/hdiutilBugTest.qUii/symlink
    Failed 85 out of 1000 times
    Working on: /tmp/hdiutilBugTest.qUii/testImage.dmg
    Failed 0 out of 1000 times

    ReplyDelete
  8. Here's a nice wrinkle, failures on a 2008 MacPro in 10.6.3 are consistent 3 times in a row:
    MacPro3,1 running Mac OS X 10.6.3 (10D573)
    Failed 4 out of 1000 times
    same machine when booted to Mac OS X 10.5.8 (9L31a) has no failures.

    ReplyDelete
  9. MacPro1,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.c1RP/symlink
     Failed 117 out of 1000 times
    Working on: /tmp/hdiutilBugTest.c1RP/testImage.dmg
     Failed 0 out of 1000 times

    ReplyDelete
  10. Here are my results. I changed the script to run it 100,000 times (Bigger sample size = better statistics). I tested it on 10.6.3 on a MacPro1,1 and then updated it to 10.6.4 and ran the same test.

    10.6.3 Tests
    MacPro1,1
    Mac OS X 10.6.3 (10D573)

    Working on: /tmp/hdiutilBugTest.Tico/symlink
    Failed 4078 out of 100000 times
    Working on: /tmp/hdiutilBugTest.Tico/testImage.dmg
    Failed 0 out of 100000 times

    Working on: /tmp/hdiutilBugTest.ZyYy/symlink
    Failed 4748 out of 100000 times
    Working on: /tmp/hdiutilBugTest.ZyYy/testImage.dmg
    Failed 0 out of 100000 times

    10.6.4 Tests

    MacPro1,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.8x0z/symlink
    Failed 4276 out of 100000 times
    Working on: /tmp/hdiutilBugTest.8x0z/testImage.dmg
    Failed 0 out of 100000 times

    Working on: /tmp/hdiutilBugTest.hlUR/symlink
    Failed 5109 out of 100000 times
    Working on: /tmp/hdiutilBugTest.hlUR/testImage.dmg
    Failed 0 out of 100000 times

    Overall, it looks like it is only slightly worse between 10.6.3 and 10.6.4. Hope that info is helpful! Thanks for all the great work you do on InstaDMG, I don't know where I would be without it.

    ReplyDelete
  11. MacBook2,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.1Ocd/symlink
    Failed 15 out of 1000 times
    ...
    Failed 17 out of 1000 times
    ...
    Failed 16 out of 1000 times

    ReplyDelete
  12. MacPro1,1
    Mac OS X 10.6.3 (10D578)
    Working on: /tmp/hdiutilBugTest.P2vi/symlink
    Failed 6 out of 1000 times
    Working on: /tmp/hdiutilBugTest.P2vi/testImage.dmg
    Failed 0 out of 1000 times

    ReplyDelete
  13. Macmini3,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.e8lU/symlink
    Failed 4008 out of 100000 times
    Working on: /tmp/hdiutilBugTest.e8lU/testImage.dmg
    Failed 0 out of 100000 times


    iMac11,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.92Bb/symlink
    Failed 688 out of 100000 times
    Working on: /tmp/hdiutilBugTest.92Bb/testImage.dmg
    Failed 0 out of 100000 times


    iMac8,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.SnVx/symlink
    Failed 1407 out of 100000 times
    Working on: /tmp/hdiutilBugTest.SnVx/testImage.dmg
    Failed 0 out of 100000 times


    MacBook4,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.AAZZ/symlink
    Failed 2437 out of 100000 times
    Working on: /tmp/hdiutilBugTest.AAZZ/testImage.dmg
    Failed 0 out of 100000 times


    MacBookPro5,1
    Mac OS X 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.tR51/symlink
    Failed 780 out of 100000 times
    Working on: /tmp/hdiutilBugTest.tR51/testImage.dmg
    Failed 0 out of 100000 times


    Xserve3,1
    Mac OS X Server 10.6.4 (10F569)
    Working on: /tmp/hdiutilBugTest.gQSs/symlink
    Failed 1617 out of 100000 times
    Working on: /tmp/hdiutilBugTest.gQSs/testImage.dmg
    Failed 0 out of 100000 times

    ReplyDelete