BUILD(macos): Fix hdiutil error during dmg packaging

The error that appeared every now and again was "no space left on
device". The exact cause and why it worked in some cases is not clear,
but with these changes it seems way more robust than before.
This commit is contained in:
Robert Adam 2021-05-13 11:21:03 +02:00
parent 0f08870da5
commit 0b75cd6f8a

View File

@ -248,14 +248,32 @@ class DiskImage(FolderObject):
Create the disk image itself.
'''
print ' * Creating diskimage. Please wait...'
if not self.filename.endswith(".dmg"):
self.filename += ".dmg"
if os.path.exists(self.filename):
os.remove(self.filename)
# First create an intermediate, uncompressed image. We do this as otherwise it often happens that
# hdiutils fails with the message "no space left on device" which doesn't seem to appear without compression
intermediateName = self.filename.replace(".dmg", "_intermediate.dmg")
p = Popen(['hdiutil', 'create',
'-srcfolder', self.tmp,
'-format', 'UDBZ',
'-format', 'UDRW',
'-volname', self.volname,
'-verbose',
intermediateName])
retval = p.wait()
if retval != 0:
raise Exception("Creating intermediate dmg file failed")
# Now take that intermediate and compress it
p = Popen(['hdiutil', 'convert',
intermediateName,
'-format', 'UDBZ',
'-verbose', '-o',
self.filename])
retval = p.wait()
if retval != 0:
raise Exception("Compressing dmg file failed")
print ' * Removing temporary directory.'
shutil.rmtree(self.tmp)
print ' * Done!'