Fix issue when mounted dmg is still in use by OSX Finder.

This commit is contained in:
Martin Zibricky 2012-12-01 13:41:58 +01:00
parent 07cceba2c6
commit 8c25375e04
1 changed files with 16 additions and 4 deletions

View File

@ -113,6 +113,8 @@ build process you can specify different make targets
import os import os
import plistlib import plistlib
import signal
import subprocess
import sys import sys
from shutil import copy, rmtree from shutil import copy, rmtree
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
@ -591,10 +593,22 @@ class MacosxBuilder(object):
u'Could not copy the background image, dmg creation failed.' u'Could not copy the background image, dmg creation failed.'
) )
print 10 * 'A'
self.adjust_dmg_view(os.path.basename(dmg_volume_path)) self.adjust_dmg_view(os.path.basename(dmg_volume_path))
# Unmount dmg file.
## Unmount dmg file.
self._print('... unmounting the dmg.') self._print('... unmounting the dmg.')
# Sometimes it could happen that OSX Finder is blocking umount.
# We need to find this process and kill it.
try:
output = subprocess.check_output(['fuser', dmg_volume_path])
blocking_proc_pid = int(output.strip().split()[0])
if blocking_proc_pid:
os.kill(int(blocking_proc_pid), signal.SIGKILL)
except:
self._print('... failed to kill process using %s' % dmg_volume_path)
# Unmount dmg file.
self._run_command([self.hdiutil, 'detach', dmg_volume_path], self._run_command([self.hdiutil, 'detach', dmg_volume_path],
'Could not unmount the dmg file, dmg creation failed.' 'Could not unmount the dmg file, dmg creation failed.'
) )
@ -639,11 +653,9 @@ class MacosxBuilder(object):
f.close() f.close()
result = p.returncode result = p.returncode
if (result != 0): if (result != 0):
self._print('Adjusting dmg view failed.') self._print('Adjusting dmg view failed (non-zero exit code).')
sys.exit(1)
except (IOError, OSError): except (IOError, OSError):
self._print('Adjusting dmg view failed.') self._print('Adjusting dmg view failed.')
sys.exit(1)
def main(self): def main(self):
""" """