KISS 🇺🇦

Stop the war!

Stop the war in Ukraine! Fuck putin!

More information is at: https://war.ukraine.ua/.

There is a fund to support the Ukrainian Army: https://savelife.in.ua/en/donate/, and there is a special bank account that accepts funds in multiple currencies: https://bank.gov.ua/en/about/support-the-armed-forces. I donated to them. Please donate if you can!

Killer putin

Killer putin. Source: politico.eu.

Arrested putin

"It hasn't happened yet, but it will happen sooner or later. Beautiful photo, isn't it?" Source: twitter.

iOS: Testing no space left situation

| comments

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# create a new 200MB RAM disk
mydev=$( 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 there
mkdir ~/"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 data
pkill -li iphone
rsync -av --delete-excluded ~/Library/Application\ Support/iPhone\ Simulator/7.1-64/{Applications/,1/}

# remount to the proper location
umount /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.

1
2
3
4
5
6
7
8
# show disk usage
df -h | grep /disk2

# unmount
umount /dev/disk2

# remove the RAM disk
diskutil eject /dev/disk2

This is a simple function that checks for this kind of error:

1
2
3
4
5
static inline BOOL isNoSpaceLeftError(NSError *error)
{
    return ([NSCocoaErrorDomain isEqualToString:error.domain] &&
            (NSFileWriteOutOfSpaceError == error.code));
}

Sources: http://osxdaily.com/2007/03/23/create-a-ram-disk-in-mac-os-x/, http://superuser.com/questions/456803/create-ram-disk-mount-to-specific-folder-in-osx.

Comments