From b6d6ea993fd3b368d28786c259bb50486aaac417 Mon Sep 17 00:00:00 2001 From: beyondkmp Date: Sat, 28 Sep 2024 08:14:46 +0800 Subject: [PATCH] fix(updater): Unable to copy file for caching: ENOENT (#8541) --- .changeset/dry-rockets-pretend.md | 5 +++++ packages/electron-updater/src/MacUpdater.ts | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 .changeset/dry-rockets-pretend.md diff --git a/.changeset/dry-rockets-pretend.md b/.changeset/dry-rockets-pretend.md new file mode 100644 index 00000000000..cabcc582098 --- /dev/null +++ b/.changeset/dry-rockets-pretend.md @@ -0,0 +1,5 @@ +--- +"electron-updater": patch +--- + +fix: Unable to copy file for caching: ENOENT diff --git a/packages/electron-updater/src/MacUpdater.ts b/packages/electron-updater/src/MacUpdater.ts index a989acb68f9..4cbb59d1a11 100644 --- a/packages/electron-updater/src/MacUpdater.ts +++ b/packages/electron-updater/src/MacUpdater.ts @@ -94,16 +94,15 @@ export class MacUpdater extends AppUpdater { const provider = downloadUpdateOptions.updateInfoAndProvider.provider const CURRENT_MAC_APP_ZIP_FILE_NAME = "update.zip" - let cachedUpdateFile: string = "" return this.executeDownload({ fileExtension: "zip", fileInfo: zipFileInfo, downloadUpdateOptions, task: async (destinationFile, downloadOptions) => { - cachedUpdateFile = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME) + const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME) const canDifferentialDownload = () => { - if (!pathExistsSync(cachedUpdateFile)) { + if (!pathExistsSync(cachedUpdateFilePath)) { log.info("Unable to locate previous update.zip for differential download (is this first install?), falling back to full download") return false } @@ -119,10 +118,13 @@ export class MacUpdater extends AppUpdater { } }, done: event => { - try { - copyFileSync(event.downloadedFile, cachedUpdateFile) - } catch (error: any) { - this._logger.error(`Unable to copy file for caching: ${error.message}`) + if (!downloadUpdateOptions.disableDifferentialDownload) { + try { + const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME) + copyFileSync(event.downloadedFile, cachedUpdateFilePath) + } catch (error: any) { + this._logger.warn(`Unable to copy file for caching for future differential downloads: ${error.message}`) + } } return this.updateDownloaded(zipFileInfo, event) },