Skip to content

Commit

Permalink
fix: use disableDifferentialDownload flag in the AppImageBuilder (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-sanderson authored Dec 31, 2024
1 parent ee2c6dc commit 819eff7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-trees-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electron-updater": patch
---

fix: respect `disableDifferentialDownload` flag for AppImage
54 changes: 28 additions & 26 deletions packages/electron-updater/src/AppImageUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand All @@ -73,6 +50,31 @@ export class AppImageUpdater extends BaseUpdater {
})
}

private async downloadDifferential(fileInfo: ResolvedUpdateFileInfo, oldFile: string, updateFile: string, provider: Provider<any>, 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) {
Expand Down

0 comments on commit 819eff7

Please sign in to comment.