Skip to content

Commit

Permalink
fix(electron-updater): Do not use multiple HTTP ranges because S3 and…
Browse files Browse the repository at this point in the history
… Minio doesn't support it
  • Loading branch information
develar committed Dec 9, 2017
1 parent 9c6843f commit 79b2ecc
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
4 changes: 3 additions & 1 deletion packages/electron-updater/src/AppImageUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export class AppImageUpdater extends BaseUpdater {

/*** @private */
protected async doDownloadUpdate(updateInfo: UpdateInfo, cancellationToken: CancellationToken): Promise<Array<string>> {
const fileInfo = findFile((await this.provider).resolveFiles(updateInfo), "AppImage")!!
const provider = await this.provider
const fileInfo = findFile(provider.resolveFiles(updateInfo), "AppImage")!!

const requestHeaders = await this.computeRequestHeaders()
const downloadOptions: DownloadOptions = {
Expand Down Expand Up @@ -62,6 +63,7 @@ export class AppImageUpdater extends BaseUpdater {
oldPackageFile: oldFile,
logger: this._logger,
newFile: installerPath,
useMultipleRangeRequest: provider.useMultipleRangeRequest,
requestHeaders,
}).download(safeLoad(await readBlockMapDataFromAppImage(oldFile)))
}
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-updater/src/GenericProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { parseUpdateInfo, resolveFiles } from "./Provider"
export class GenericProvider extends Provider<UpdateInfo> {
private readonly baseUrl = newBaseUrl(this.configuration.url)

constructor(private readonly configuration: GenericServerOptions, private readonly updater: AppUpdater) {
super(updater.httpExecutor)
constructor(private readonly configuration: GenericServerOptions, private readonly updater: AppUpdater, useMultipleRangeRequest = true) {
super(updater.httpExecutor, useMultipleRangeRequest)
}

private get channel(): string {
Expand Down
10 changes: 6 additions & 4 deletions packages/electron-updater/src/NsisUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { CancellationToken, DownloadOptions, AllPublishOptions, UpdateInfo } from "builder-util-runtime"
import { AllPublishOptions, CancellationToken, DownloadOptions, UpdateInfo } from "builder-util-runtime"
import { BLOCK_MAP_FILE_NAME } from "builder-util-runtime/out/blockMapApi"
import { spawn } from "child_process"
import * as path from "path"
import "source-map-support/register"
import { BaseUpdater } from "./BaseUpdater"
import { SevenZipDifferentialDownloader } from "./differentialDownloader/SevenZipDifferentialDownloader"
import { UPDATE_DOWNLOADED } from "./main"
import { verifySignature } from "./windowsExecutableCodeSignatureVerifier"
import { BaseUpdater } from "./BaseUpdater"
import { findFile } from "./Provider"
import { verifySignature } from "./windowsExecutableCodeSignatureVerifier"

export class NsisUpdater extends BaseUpdater {
constructor(options?: AllPublishOptions | null, app?: any) {
Expand All @@ -16,7 +16,8 @@ export class NsisUpdater extends BaseUpdater {

/*** @private */
protected async doDownloadUpdate(updateInfo: UpdateInfo, cancellationToken: CancellationToken): Promise<Array<string>> {
const fileInfo = findFile((await this.provider).resolveFiles(updateInfo), "exe")!!
const provider = await this.provider
const fileInfo = findFile(provider.resolveFiles(updateInfo), "exe")!!
const requestHeaders = await this.computeRequestHeaders()
const downloadOptions: DownloadOptions = {
skipDirCreation: true,
Expand Down Expand Up @@ -51,6 +52,7 @@ export class NsisUpdater extends BaseUpdater {
logger: this._logger,
newFile: packagePath,
requestHeaders: this.requestHeaders,
useMultipleRangeRequest: provider.useMultipleRangeRequest,
}).download(path.join(process.resourcesPath!, "..", BLOCK_MAP_FILE_NAME))
}
catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-updater/src/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { newUrlFromBase, ResolvedUpdateFileInfo } from "./main"
export abstract class Provider<T extends UpdateInfo> {
protected requestHeaders: OutgoingHttpHeaders | null

constructor(protected readonly executor: HttpExecutor<any>) {
constructor(protected readonly executor: HttpExecutor<any>, readonly useMultipleRangeRequest = true) {
}

get fileExtraDownloadHeaders(): OutgoingHttpHeaders | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class DifferentialDownloaderOptions {
readonly newFile: string

readonly requestHeaders: OutgoingHttpHeaders | null

readonly useMultipleRangeRequest?: boolean
}

export abstract class DifferentialDownloader {
Expand Down Expand Up @@ -81,7 +83,6 @@ export abstract class DifferentialDownloader {
}

private async downloadFile(tasks: Array<Operation>): Promise<any> {
// todo we can avoid download remote and construct manually
const signature = this.signatureSize === 0 ? null : await this.readRemoteBytes(0, this.signatureSize - 1)

const oldFileFd = await open(this.options.oldPackageFile, "r")
Expand Down Expand Up @@ -129,7 +130,7 @@ export abstract class DifferentialDownloader {
return
}

const nextOffset = taskOffset + 2000
const nextOffset = taskOffset + (this.options.useMultipleRangeRequest === false ? 1 : 1000)
this.executeTasks({
tasks,
start: taskOffset,
Expand Down
6 changes: 3 additions & 3 deletions packages/electron-updater/src/providerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export function createClient(data: PublishConfiguration | AllPublishOptions, upd
return new GenericProvider({
provider: "generic",
url: getS3LikeProviderBaseUrl(data),
channel: (data as BaseS3Options).channel || ""
}, updater)
channel: (data as BaseS3Options).channel || null
}, updater, provider === "spaces" /* https://github.com/minio/minio/issues/5285#issuecomment-350428955 */)

case "generic":
return new GenericProvider(data as GenericServerOptions, updater)
return new GenericProvider(data as GenericServerOptions, updater, true)

case "bintray":
return new BintrayProvider(data as BintrayOptions, httpExecutor)
Expand Down
4 changes: 4 additions & 0 deletions test/src/helpers/updaterTestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export function createTestApp(version: string, appPath = "") {
// ignored
}

once() {
// ignored
}

isReady() {
return true
}
Expand Down

0 comments on commit 79b2ecc

Please sign in to comment.