From 819eff7bf7f319275d70faf3a64a5a18a3793a7c Mon Sep 17 00:00:00 2001 From: Peter Sanderson <152899911+peter-sanderson@users.noreply.github.com> Date: Tue, 31 Dec 2024 20:07:29 +0100 Subject: [PATCH] fix: use `disableDifferentialDownload` flag in the AppImageBuilder (#8695) --- .changeset/odd-trees-battle.md | 5 ++ .../electron-updater/src/AppImageUpdater.ts | 54 ++++++++++--------- 2 files changed, 33 insertions(+), 26 deletions(-) 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 diff --git a/packages/electron-updater/src/AppImageUpdater.ts b/packages/electron-updater/src/AppImageUpdater.ts index a498ac13bee..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,30 +41,7 @@ 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, - } - - 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) } @@ -73,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) {