puppetlabs/puppet — pull request #2366 by keithduncan (2014-02-18 14:32:12+00:00)
Title: pkgdmg should copy the contents of each mountpoint and install from there

I’ve been seeing `EBUSY` failures when unmounting dmgs and captured the processes that still have open files with `lsof` after running puppet.

```
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mds 43 root 15r DIR 1,4 238 2 /private/tmp/dmg.uQT3Dp
installd 691 root 4r REG 1,4 30079000 132 /private/tmp/dmg.uQT3Dp/Packages/MacOSX10_9_SDK.pkg
installd 691 root 5r REG 1,4 30079000 132 /private/tmp/dmg.uQT3Dp/Packages/MacOSX10_9_SDK.pkg
installer 3164 root 4r REG 1,4 657793 130 /private/tmp/dmg.uQT3Dp/Command Line Tools (OS X 10.9).pkg
```

`mds` is harmless but I didn’t want to unmount the dmg with `-force` and interfere with whatever `installd` or `installer` is doing with the packages.

To fix these errors I’ve copied the contents of each mountpoint, and then passed the paths of those copied pkg files to installer. This ensures the pkg files passed to installer are on the root volume and that the mounted volume can be safely ejected with `-force` thus preventing the unmount from failing because errant background processes like Spotlight have files open on the volume.

Removing the temporary directory unlinks the files but leaves the files intact so long as processes have open descriptors to them, the files are then reclaimed when the lingering descriptors are closed.