@@ -4,7 +4,7 @@ import MacPackager from "app-builder-lib/out/macPackager"
44import { createBlockmap } from "app-builder-lib/out/targets/differentialUpdateInfoBuilder"
55import { executeAppBuilderAsJson } from "app-builder-lib/out/util/appBuilder"
66import { sanitizeFileName } from "app-builder-lib/out/util/filename"
7- import { Arch , AsyncTaskManager , exec , getArchSuffix , InvalidConfigurationError , isEmptyOrSpaces , log , spawn , retry } from "builder-util"
7+ import { Arch , AsyncTaskManager , exec , getArchSuffix , InvalidConfigurationError , isEmptyOrSpaces , log } from "builder-util"
88import { CancellationToken } from "builder-util-runtime"
99import { copyDir , copyFile , exists , statOrNull } from "builder-util/out/fs"
1010import { stat } from "fs-extra"
@@ -13,6 +13,7 @@ import { TmpDir } from "temp-file"
1313import { addLicenseToDmg } from "./dmgLicense"
1414import { attachAndExecute , computeBackground , detach , getDmgVendorPath } from "./dmgUtil"
1515import { release as getOsRelease } from "os"
16+ import { hdiUtil } from "./hdiuil"
1617
1718export class DmgTarget extends Target {
1819 readonly options : DmgOptions = this . packager . config . dmg || Object . create ( null )
@@ -51,7 +52,7 @@ export class DmgTarget extends Target {
5152 const backgroundFile = specification . background == null ? null : await transformBackgroundFileIfNeed ( specification . background , packager . info . tempDirManager )
5253 const finalSize = await computeAssetSize ( packager . info . cancellationToken , tempDmg , specification , backgroundFile )
5354 const expandingFinalSize = finalSize * 0.1 + finalSize
54- await exec ( "hdiutil" , [ "resize" , "-size" , expandingFinalSize . toString ( ) , tempDmg ] )
55+ await hdiUtil ( [ "resize" , "-size" , expandingFinalSize . toString ( ) , tempDmg ] )
5556
5657 const volumePath = path . join ( "/Volumes" , volumeName )
5758 if ( await exists ( volumePath ) ) {
@@ -68,9 +69,9 @@ export class DmgTarget extends Target {
6869 if ( specification . format === "UDZO" ) {
6970 args . push ( "-imagekey" , `zlib-level=${ process . env . ELECTRON_BUILDER_COMPRESSION_LEVEL || "9" } ` )
7071 }
71- await spawn ( "hdiutil" , addLogLevel ( args ) )
72+ await hdiUtil ( addLogLevel ( args ) )
7273 if ( this . options . internetEnabled && parseInt ( getOsRelease ( ) . split ( "." ) [ 0 ] , 10 ) < 19 ) {
73- await exec ( "hdiutil" , addLogLevel ( [ "internet-enable" ] ) . concat ( artifactPath ) )
74+ await hdiUtil ( addLogLevel ( [ "internet-enable" ] ) . concat ( artifactPath ) )
7475 }
7576
7677 const licenseData = await addLicenseToDmg ( packager , artifactPath )
@@ -210,9 +211,7 @@ async function createStageDmg(tempDmg: string, appPath: string, volumeName: stri
210211 }
211212 imageArgs . push ( "-fs" , ...filesystem )
212213 imageArgs . push ( tempDmg )
213- // The reason for retrying up to ten times is that hdiutil create in some cases fail to unmount due to "resource busy".
214- // https://github.com/electron-userland/electron-builder/issues/5431
215- await retry ( ( ) => spawn ( "hdiutil" , imageArgs ) , 5 , 1000 )
214+ await hdiUtil ( imageArgs )
216215 return tempDmg
217216}
218217
0 commit comments