From a65b446d7885a5f57241e48c41d9aa0045278d5f Mon Sep 17 00:00:00 2001 From: Peter Sanderson Date: Thu, 21 Nov 2024 10:22:58 +0100 Subject: [PATCH 1/3] fix: use disableDifferentialDownload flag in the AppImageBuilder --- .../electron-updater/src/AppImageUpdater.ts | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/packages/electron-updater/src/AppImageUpdater.ts b/packages/electron-updater/src/AppImageUpdater.ts index a498ac13bee..837ccd768d4 100644 --- a/packages/electron-updater/src/AppImageUpdater.ts +++ b/packages/electron-updater/src/AppImageUpdater.ts @@ -41,27 +41,29 @@ export class AppImageUpdater extends BaseUpdater { throw newError("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND") } - let isDownloadFull = false - try { - const downloadOptions: DifferentialDownloaderOptions = { - newUrl: fileInfo.url, - oldFile, - logger: this._logger, - newFile: updateFile, - isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest, - requestHeaders: downloadUpdateOptions.requestHeaders, - cancellationToken: downloadUpdateOptions.cancellationToken, - } + let isDownloadFull = downloadUpdateOptions.disableDifferentialDownload + if (!isDownloadFull) { + try { + const downloadOptions: DifferentialDownloaderOptions = { + newUrl: fileInfo.url, + oldFile, + logger: this._logger, + newFile: updateFile, + isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest, + requestHeaders: downloadUpdateOptions.requestHeaders, + cancellationToken: downloadUpdateOptions.cancellationToken, + } - if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) { - downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it) - } + if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) { + downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it) + } - await new FileWithEmbeddedBlockMapDifferentialDownloader(fileInfo.info, this.httpExecutor, downloadOptions).download() - } catch (e: any) { - this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`) - // during test (developer machine mac) we must throw error - isDownloadFull = process.platform === "linux" + await new FileWithEmbeddedBlockMapDifferentialDownloader(fileInfo.info, this.httpExecutor, downloadOptions).download() + } catch (e: any) { + this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`) + // during test (developer machine mac) we must throw error + isDownloadFull = process.platform === "linux" + } } if (isDownloadFull) { From 03652f9b58874d0f0ec66f3fd0aa3800c7c1ea66 Mon Sep 17 00:00:00 2001 From: Mike Maietta Date: Thu, 21 Nov 2024 06:51:59 -0800 Subject: [PATCH 2/3] Create odd-trees-battle.md --- .changeset/odd-trees-battle.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/odd-trees-battle.md diff --git a/.changeset/odd-trees-battle.md b/.changeset/odd-trees-battle.md new file mode 100644 index 00000000000..46c4252edcc --- /dev/null +++ b/.changeset/odd-trees-battle.md @@ -0,0 +1,5 @@ +--- +"electron-updater": patch +--- + +fix: respect `disableDifferentialDownload` flag for AppImage From a32b59476db473d67c15f2a5b7022aff31b56429 Mon Sep 17 00:00:00 2001 From: Mike Maietta Date: Fri, 6 Dec 2024 08:52:33 -0800 Subject: [PATCH 3/3] small refactor/extraction of differential logic (mirrors windows differential if-logic) --- .../electron-updater/src/AppImageUpdater.ts | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/electron-updater/src/AppImageUpdater.ts b/packages/electron-updater/src/AppImageUpdater.ts index 837ccd768d4..150ec21ae65 100644 --- a/packages/electron-updater/src/AppImageUpdater.ts +++ b/packages/electron-updater/src/AppImageUpdater.ts @@ -7,8 +7,8 @@ import { DownloadUpdateOptions } from "./AppUpdater" import { BaseUpdater, InstallOptions } from "./BaseUpdater" import { DifferentialDownloaderOptions } from "./differentialDownloader/DifferentialDownloader" import { FileWithEmbeddedBlockMapDifferentialDownloader } from "./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader" -import { DOWNLOAD_PROGRESS } from "./main" -import { findFile } from "./providers/Provider" +import { DOWNLOAD_PROGRESS, ResolvedUpdateFileInfo } from "./main" +import { findFile, Provider } from "./providers/Provider" export class AppImageUpdater extends BaseUpdater { constructor(options?: AllPublishOptions | null, app?: any) { @@ -41,32 +41,7 @@ export class AppImageUpdater extends BaseUpdater { throw newError("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND") } - let isDownloadFull = downloadUpdateOptions.disableDifferentialDownload - if (!isDownloadFull) { - try { - const downloadOptions: DifferentialDownloaderOptions = { - newUrl: fileInfo.url, - oldFile, - logger: this._logger, - newFile: updateFile, - isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest, - requestHeaders: downloadUpdateOptions.requestHeaders, - cancellationToken: downloadUpdateOptions.cancellationToken, - } - - if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) { - downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it) - } - - await new FileWithEmbeddedBlockMapDifferentialDownloader(fileInfo.info, this.httpExecutor, downloadOptions).download() - } catch (e: any) { - this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`) - // during test (developer machine mac) we must throw error - isDownloadFull = process.platform === "linux" - } - } - - if (isDownloadFull) { + if (downloadUpdateOptions.disableDifferentialDownload || (await this.downloadDifferential(fileInfo, oldFile, updateFile, provider, downloadUpdateOptions))) { await this.httpExecutor.download(fileInfo.url, updateFile, downloadOptions) } @@ -75,6 +50,31 @@ export class AppImageUpdater extends BaseUpdater { }) } + private async downloadDifferential(fileInfo: ResolvedUpdateFileInfo, oldFile: string, updateFile: string, provider: Provider, downloadUpdateOptions: DownloadUpdateOptions) { + try { + const downloadOptions: DifferentialDownloaderOptions = { + newUrl: fileInfo.url, + oldFile, + logger: this._logger, + newFile: updateFile, + isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest, + requestHeaders: downloadUpdateOptions.requestHeaders, + cancellationToken: downloadUpdateOptions.cancellationToken, + } + + if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) { + downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it) + } + + await new FileWithEmbeddedBlockMapDifferentialDownloader(fileInfo.info, this.httpExecutor, downloadOptions).download() + return false + } catch (e: any) { + this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`) + // during test (developer machine mac) we must throw error + return process.platform === "linux" + } + } + protected doInstall(options: InstallOptions): boolean { const appImageFile = process.env["APPIMAGE"]! if (appImageFile == null) {