How do you test that your app handles “no space left on device” errors properly? There is a (boring) way to stuff up your device until it’s full and test that way. It’s not the most convenient way though, especially if you want to test faster on the iOS Simulator. Here’s my solution: mount a small RAM disk for the Applications directory in the simulator.
Following are the commands to prepare and mount a RAM disk:
1234567891011121314151617181920212223
# create a new 200MB RAM diskmydev=$( hdiutil attach -nomount ram://$((200*1024*1024/512)))# (optional) should print the new disk:diskutil list
# create a new FS on it (here, /dev/disk2 is the created disk; I naturally tried# using $mydev for that and failed with an error about /dev/rdisk2, although the# value was indeed /dev/disk2)newfs_hfs /dev/disk2
# as mounting will hide the existing files, we need to copy them over first# make an arbitrary directory and mount theremkdir ~/"Library/Application Support/iPhone Simulator/7.1-64/1/"mount -t hfs /dev/disk2 ~/"Library/Application Support/iPhone Simulator/7.1-64/1/"# kill the iOS Simulator and copy the datapkill -li iphone
rsync -av --delete-excluded ~/Library/Application\ Support/iPhone\ Simulator/7.1-64/{Applications/,1/}# remount to the proper locationumount /dev/disk2
mount -t hfs /dev/disk2 ~/"Library/Application Support/iPhone Simulator/7.1-64/Applications/"
Now you can easily fill up this virtual disk. Please note the data will be destroyed on OS restart or disk ejection.
12345678
# show disk usagedf -h | grep /disk2
# unmountumount /dev/disk2
# remove the RAM diskdiskutil eject /dev/disk2
This is a simple function that checks for this kind of error: