From b6b99c57f6794818b396865583a3b796f85d23b4 Mon Sep 17 00:00:00 2001 From: Juwon Jung Date: Fri, 30 Aug 2024 19:01:32 +0900 Subject: [PATCH] fix: retry renaming update file when EBUSY error occurs due to file lock --- packages/electron-updater/package.json | 1 + packages/electron-updater/src/AppUpdater.ts | 10 +++++++++- pnpm-lock.yaml | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/electron-updater/package.json b/packages/electron-updater/package.json index c732d4331a7..11a700781e9 100644 --- a/packages/electron-updater/package.json +++ b/packages/electron-updater/package.json @@ -16,6 +16,7 @@ "out" ], "dependencies": { + "builder-util": "workspace:*", "builder-util-runtime": "workspace:*", "fs-extra": "^10.1.0", "js-yaml": "^4.1.0", diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index 12d615de74f..bbc5fea291d 100644 --- a/packages/electron-updater/src/AppUpdater.ts +++ b/packages/electron-updater/src/AppUpdater.ts @@ -1,3 +1,4 @@ +import { retry } from "builder-util" import { AllPublishOptions, asArray, @@ -712,7 +713,14 @@ export abstract class AppUpdater extends (EventEmitter as new () => TypedEmitter const tempUpdateFile = await createTempUpdateFile(`temp-${updateFileName}`, cacheDir, log) try { await taskOptions.task(tempUpdateFile, downloadOptions, packageFile, removeFileIfAny) - await rename(tempUpdateFile, updateFile) + await retry( + () => rename(tempUpdateFile, updateFile), + 60, + 500, + 0, + 0, + error => error instanceof Error && /^EBUSY:/.test(error.message) + ) } catch (e: any) { await removeFileIfAny() diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9aee581ed82..4c10c7b72e3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -514,6 +514,9 @@ importers: packages/electron-updater: dependencies: + builder-util: + specifier: workspace:* + version: link:../builder-util builder-util-runtime: specifier: workspace:* version: link:../builder-util-runtime