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AAM,IAAI,MAAM,EAAE,CAAC,IAAI,EAAE,CAAA;IAE3C,MAAM,SAAS,GAAG,iCAAyB,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;IAChE,kBAAG,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,kBAAkB,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAE1F,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAEM,KAAK,UAAU,OAAO,CAAC,IAAc;IAC1C,OAAO,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,IAAA,mBAAI,EAAC,SAAS,EAAE,IAAI,CAAC,EAAE;QACxC,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,WAAW,CAAC,IAAI,CAAC;KAC/B,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { exec, log, retry } from \"builder-util\"\n\n/**\n * Table of hdiutil error codes that are transient and can be retried.\n * These codes are typically related to resource availability or temporary issues.\n *\n| Code    | Meaning                          | Why Retry?                                           |\n| ------- | -------------------------------- | ---------------------------------------------------- |\n| `1`     | Generic error                    | Can occur from brief race conditions or temp issues. |\n| `16`    | **Resource busy**                | Volume is in use — wait and retry often works.       |\n| `35`    | **Operation timed out**          | System delay or timeout — retry after a short delay. |\n| `256`   | Volume in use or unmount failure | Same as 16 — usually resolves after retry.           |\n| `49153` | Volume not mounted yet           | Attach may be too fast — retry after delay.          |\n| `-5341` | Disk image too small             | Retry *after fixing* with a larger `-size`.          |\n| `-5342` | Specified size too small         | Same as above — retry if size is corrected.          |\n *\n */\nexport const hdiutilTransientExitCodes = new Set([1, 16, 35, 256, 49153])\n\nexport function explainHdiutilError(errorCode: number): string {\n  const code = errorCode.toString()\n  const messages: Record<string, string> = {\n    \"0\": \"Success: The hdiutil command completed without error.\",\n    \"1\": \"Generic error: The operation failed, but the reason is not specific. Check command syntax or permissions.\",\n    \"2\": \"No such file or directory: Check if the specified path exists.\",\n    \"6\": \"Disk image to resize is not currently attached or not recognized as a valid block device by macOS.\",\n    \"8\": \"Exec format error: The file might not be a valid disk image.\",\n    \"16\": \"Resource busy: The volume is in use. Try closing files or processes and retry.\",\n    \"22\": \"Invalid argument: One or more arguments passed to hdiutil are incorrect.\",\n    \"35\": \"Operation timed out: The system was too slow or unresponsive. Try again.\",\n    \"36\": \"I/O error: There was a problem reading or writing to disk. Check disk health.\",\n    \"100\": \"Image-related error: The disk image may be corrupted or invalid.\",\n    \"256\": \"Volume is busy or could not be unmounted. Try again after closing files.\",\n    \"49153\": \"Volume not mounted yet: The image may not have been fully attached.\",\n    \"-5341\": \"Disk image too small: hdiutil could not fit the contents. Increase the image size.\",\n    \"-5342\": \"Specified size too small: Disk image creation failed due to insufficient size.\",\n  }\n\n  return messages[code] ?? `Unknown error (code ${code}): Refer to hdiutil documentation or run with -verbose for details by rerunning with env var DEBUG_DEMB=true.`\n}\n\nconst shouldRetry = (args: string[]) => (error: any) => {\n  const code = error.code ?? -1\n  const stderr = error.stderr?.toString() || \"\"\n  const stdout = error.stdout?.toString() || \"\"\n  const output = `${stdout} ${stderr}`.trim()\n\n  const willRetry = hdiutilTransientExitCodes.has(code.toString())\n  log.warn({ willRetry, args, code, output }, `hdiutil error: ${explainHdiutilError(code)}`)\n\n  return willRetry\n}\n\nexport async function hdiUtil(args: string[]): Promise<string | null> {\n  return retry(() => exec(\"hdiutil\", args), {\n    retries: 5,\n    interval: 5000,\n    backoff: 2000,\n    shouldRetry: shouldRetry(args),\n  })\n}\n"]}