Retry every hdiutil operation

On newer macOS version hdiutil fails even more often
This commit is contained in:
Dmitry Vedenko 2024-03-26 12:57:20 +03:00
parent 71e220d61c
commit 5dee4e7a97
No known key found for this signature in database
GPG Key ID: F4C37A6204F983A2
2 changed files with 62 additions and 25 deletions

File diff suppressed because one or more lines are too long

View File

@ -60,6 +60,11 @@ async function detachImage(mountedPath) {
for (let attempt = 1; attempt < maxAttempts; ++attempt) {
try {
if (!fs.existsSync(mountedPath)) {
helpers.log(`Image ${mountedPath} already detached`);
return;
}
return await helpers.execWithLog('hdiutil', [
'detach', mountedPath
]);
@ -68,17 +73,27 @@ async function detachImage(mountedPath) {
await helpers.sleep(2000 * attempt);
}
}
try {
if (!fs.existsSync(mountedPath)) {
helpers.log(`Image ${mountedPath} already detached`);
return;
}
return await helpers.execWithLog('hdiutil', [
'detach', mountedPath, '-force'
]);
} catch (err) {
helpers.error(err.message);
throw new Error(`Failed to detach image ${mountedPath}`);
}
}
async function attachImage(imagePath, finalizers) {
const maxAttempts = 10;
for (let attempt = 1; attempt < maxAttempts; ++attempt) {
try {
const output = await helpers.getExecOutput('hdiutil', [
'attach', imagePath,
'-nobrowse',
@ -97,6 +112,13 @@ async function attachImage(imagePath, finalizers) {
});
return mountedPath;
} catch (err) {
helpers.error(err.message);
await helpers.sleep(2000 * attempt);
}
}
throw new Error(`Failed to attach image ${imagePath}`);
}
async function copyFiles(targetDir, appDir, files) {
@ -151,6 +173,10 @@ async function createDSStore(mountPath, name) {
}
async function convertDMG(tempDmgPath, dmgPath) {
const maxAttempts = 10;
for (let attempt = 1; attempt < maxAttempts; ++attempt) {
try {
if (fs.existsSync(dmgPath)){
fs.rmSync(dmgPath);
}
@ -162,6 +188,17 @@ async function convertDMG(tempDmgPath, dmgPath) {
'zlib-level=9',
'-o', dmgPath
]);
return;
} catch (err) {
helpers.error(err.message);
await helpers.sleep(2000 * attempt);
}
}
if (!fs.existsSync(dmgPath)) {
throw new Error(`Failed to convert image ${tempDmgPath} to ${dmgPath}`);
}
}
async function packageDMG(dmgPath, appPath) {