Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: github private repo differential updates #6198

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/metal-mugs-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electron-updater": patch
---

fix: fixing fetching blockmaps for differential updates when github private repos
14 changes: 13 additions & 1 deletion packages/electron-updater/src/NsisUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,19 @@ export class NsisUpdater extends BaseUpdater {
if (this._testOnlyOptions != null && !this._testOnlyOptions.isUseDifferentialDownload) {
return true
}
const blockmapFileUrls = blockmapFiles(fileInfo.url, this.app.version, downloadUpdateOptions.updateInfoAndProvider.info.version)

let blockmapFileUrls: URL[]
if (fileInfo.updateFileUrls) {
const oldBlockmap = fileInfo.updateFileUrls.old.find(it => it.name.endsWith(".blockmap"))
const newBlockmap = fileInfo.updateFileUrls.new.find(it => it.name.endsWith(".blockmap"))
if (!oldBlockmap || !newBlockmap) {
throw new Error(`Blockmap file not found (old: [name: "${oldBlockmap?.name}" url: "${oldBlockmap?.url}"] new: [name: "${newBlockmap?.name}" url: "${newBlockmap?.url}"])`)
}
blockmapFileUrls = [oldBlockmap.url, newBlockmap.url]
} else {
blockmapFileUrls = blockmapFiles(fileInfo.url, this.app.version, downloadUpdateOptions.updateInfoAndProvider.info.version)
}

this._logger.info(`Download block maps (old: "${blockmapFileUrls[0]}", new: ${blockmapFileUrls[1]})`)

const downloadBlockMap = async (url: URL): Promise<BlockMap> => {
Expand Down
10 changes: 10 additions & 0 deletions packages/electron-updater/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,19 @@ export interface ResolvedUpdateFileInfo {
readonly url: URL
readonly info: UpdateFileInfo

updateFileUrls?: {
new: UpdateFileUrl[]
old: UpdateFileUrl[]
}

packageInfo?: PackageFileInfo
}

export interface UpdateFileUrl {
name: string
url: URL
}

export interface UpdateCheckResult {
readonly updateInfo: UpdateInfo

Expand Down
24 changes: 24 additions & 0 deletions packages/electron-updater/src/providers/PrivateGitHubProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getFileList, ProviderRuntimeOptions } from "./Provider"

export interface PrivateGitHubUpdateInfo extends UpdateInfo {
assets: Array<Asset>
currentVersionAssets: Array<Asset>
}

export class PrivateGitHubProvider extends BaseGitHubProvider<PrivateGitHubUpdateInfo> {
Expand All @@ -29,6 +30,8 @@ export class PrivateGitHubProvider extends BaseGitHubProvider<PrivateGitHubUpdat
const channelFile = getChannelFilename(this.getDefaultChannelName())

const releaseInfo = await this.getLatestVersionInfo(cancellationToken)
const currentInfo = await this.getVersionInfo(this.updater.currentVersion.version, cancellationToken)

const asset = releaseInfo.assets.find(it => it.name === channelFile)
if (asset == null) {
// html_url must be always, but just to be sure
Expand All @@ -47,6 +50,8 @@ export class PrivateGitHubProvider extends BaseGitHubProvider<PrivateGitHubUpdat
}

;(result as PrivateGitHubUpdateInfo).assets = releaseInfo.assets
;(result as PrivateGitHubUpdateInfo).currentVersionAssets = currentInfo.assets

return result
}

Expand Down Expand Up @@ -82,10 +87,25 @@ export class PrivateGitHubProvider extends BaseGitHubProvider<PrivateGitHubUpdat
}
}

async getVersionInfo(version: string, cancellationToken: CancellationToken): Promise<ReleaseInfo> {
const url = this.getVersionUrl(version)
try {
const version = JSON.parse((await this.httpRequest(url, this.configureHeaders("application/vnd.github.v3+json"), cancellationToken))!)
return version
} catch (e) {
throw newError(`Unable to find version ${version} on GitHub (${url}), please ensure a production release exists: ${e.stack || e.message}`, "ERR_UPDATER_VERSION_NOT_FOUND")
}
}

private get basePath(): string {
return this.computeGithubBasePath(`/repos/${this.options.owner}/${this.options.repo}/releases`)
}

private getVersionUrl(version: string): URL {
const tagName = this.options.vPrefixedTagName === false ? version : `v${version}`
return newUrlFromBase(`/repos/${this.options.owner}/${this.options.repo}/releases/tags/${tagName}`, this.baseApiUrl)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test using this?

return newUrlFromBase(`/repos/${this.options.owner}/${this.options.repo}/releases/tags/${tagName}`, this.baseApiUrl)

Copy link
Author

@NGrey5 NGrey5 Aug 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as well! The only issue I'm still running into is the following:

[2021-08-30 07:52:19.230] [info]  Checking for update
[2021-08-30 07:52:20.194] [info]  Found version 0.0.2 (url: Electron-Update-Test-Setup-0.0.2.exe)
[2021-08-30 07:52:20.194] [info]  Downloading update from Electron-Update-Test-Setup-0.0.2.exe
[2021-08-30 07:52:20.197] [info]  Download block maps (old: "https://api.github.com/repos/NGrey5/electron-update-test/releases/assets/43620195", new: https://api.github.com/repos/NGrey5/electron-update-test/releases/assets/43620268)
[2021-08-30 07:52:20.371] [info]  File has 35 changed blocks
[2021-08-30 07:52:20.381] [info]  Full: 57,990.1 KB, To download: 764.79 KB (1%)
[2021-08-30 07:52:20.384] [info]  Differential download: https://api.github.com/repos/NGrey5/electron-update-test/releases/assets/43620267
[2021-08-30 07:52:21.401] [error] Cannot download differentially, fallback to full download: Error: sha512 checksum mismatch, expected JhtI6yn2plziVTLgNT6nN7OS1eA6GQlL3zsKsymDwkv/EjtOQqV0kpJP6RXYdabYlvJUxsFMB0oCKQWV4HsGyQ==, got OpLHghzGPj+9sbeUN/wxkIazBxwtbVuxMZKbNz2YRMRxAICu9jhj2cgfLVnaLYajgLAI7kHZJERRYATnQfaCZQ==
    at Object.newError (C:\Users\NGrey\AppData\Local\Programs\Electron Update Test\resources\app.asar\node_modules\builder-util-runtime\out\index.js:47:19)
    at DigestTransform.validate (C:\Users\NGrey\AppData\Local\Programs\Electron Update Test\resources\app.asar\node_modules\builder-util-runtime\out\httpExecutor.js:355:27)
    at WriteStream.<anonymous> (C:\Users\NGrey\AppData\Local\Programs\Electron Update Test\resources\app.asar\node_modules\electron-updater\out\differentialDownloader\DifferentialDownloader.js:133:41)
    at WriteStream.emit (events.js:315:20)
    at emitCloseNT (internal/streams/destroy.js:87:10)
    at processTicksAndRejections (internal/process/task_queues.js:79:21)
[2021-08-30 07:52:26.008] [info]  New version 0.0.2 has been downloaded to C:\Users\NGrey\AppData\Local\electron update test-updater\pending\update.exe

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try that again and see what files it is comparing?
I'm curious if it's comparing a blockmap checksum with the executable checksum on accident.
You can add logging to the autoupdater via:

    const log = require("electron-log")
    log.transports.file.level = "debug"
    autoUpdater.logger = log

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the output for debug. I think it's important to note that a Public github repo doesn't have any checksum error. It's almost as if the info we're trying to get from the github API isn't the same. I've pasted in both debugs for both private and public.

PRIVATE GITHUB REPO
[2021-08-31 07:47:19.819] [info]  Checking for update
[2021-08-31 07:47:19.838] [info]  Generated new staging user ID: 8e2c8251-81a3-5053-9660-b4c8a52d305e
[2021-08-31 07:47:20.881] [info]  Found version 0.0.2 (url: ElectronUpdateTestSetup.exe)
[2021-08-31 07:47:20.881] [info]  Downloading update from ElectronUpdateTestSetup.exe
[2021-08-31 07:47:20.883] [debug] updater cache dir: C:\Users\NGrey\AppData\Local\electron update test-updater
[2021-08-31 07:47:20.885] [info]  Download block maps (old: "https://api.github.com/repos/NGrey5/electron-update-test/releases/assets/43663242", new: https://api.github.com/repos/NGrey5/electron-update-test/releases/assets/43663314)
[2021-08-31 07:47:21.096] [info]  File has 35 changed blocks
[2021-08-31 07:47:21.097] [debug] [
  {
    "kind": 0,
    "start": 0,
    "end": 211730
  },
  {
    "kind": 1,
    "start": 211730,
    "end": 267840
  },
  {
    "kind": 0,
    "start": 267835,
    "end": 314321
  },
  {
    "kind": 1,
    "start": 314326,
    "end": 336894
  },
  {
    "kind": 0,
    "start": 336889,
    "end": 10484878
  },
  {
    "kind": 1,
    "start": 10484883,
    "end": 10951925
  },
  {
    "kind": 0,
    "start": 10952018,
    "end": 49629754
  },
  {
    "kind": 1,
    "start": 49629661,
    "end": 49645896
  },
  {
    "kind": 0,
    "start": 49645989,
    "end": 49672900
  },
  {
    "kind": 1,
    "start": 49672807,
    "end": 49782511
  },
  {
    "kind": 0,
    "start": 49782625,
    "end": 58935645
  },
  {
    "kind": 1,
    "start": 58935531,
    "end": 58968299
  },
  {
    "kind": 0,
    "start": 58968413,
    "end": 59201214
  },
  {
    "kind": 1,
    "start": 59201100,
    "end": 59210764
  },
  {
    "kind": 0,
    "start": 59210878,
    "end": 59270290
  },
  {
    "kind": 1,
    "start": 59270176,
    "end": 59381894
  }
]
[2021-08-31 07:47:21.106] [info]  Full: 57,990.13 KB, To download: 806.45 KB (1%)
[2021-08-31 07:47:21.109] [info]  Differential download: https://api.github.com/repos/NGrey5/electron-update-test/releases/assets/43663315
[2021-08-31 07:47:21.112] [debug] download range: bytes=211730-267839
[2021-08-31 07:47:21.213] [debug] download range: bytes=314326-336893
[2021-08-31 07:47:21.342] [debug] download range: bytes=10484883-10951924
[2021-08-31 07:47:21.578] [debug] download range: bytes=49629661-49645895
[2021-08-31 07:47:21.666] [debug] download range: bytes=49672807-49782510
[2021-08-31 07:47:21.847] [debug] download range: bytes=58935531-58968298
[2021-08-31 07:47:21.956] [debug] download range: bytes=59201100-59210763
[2021-08-31 07:47:22.054] [debug] download range: bytes=59270176-59381893
[2021-08-31 07:47:22.145] [error] Cannot download differentially, fallback to full download: Error: sha512 checksum mismatch, expected JhtI6yn2plziVTLgNT6nN7OS1eA6GQlL3zsKsymDwkv/EjtOQqV0kpJP6RXYdabYlvJUxsFMB0oCKQWV4HsGyQ==, got OpLHghzGPj+9sbeUN/wxkIazBxwtbVuxMZKbNz2YRMRxAICu9jhj2cgfLVnaLYajgLAI7kHZJERRYATnQfaCZQ==
    at Object.newError (C:\Users\NGrey\AppData\Local\Programs\Electron Update Test\resources\app.asar\node_modules\builder-util-runtime\out\index.js:47:19)
    at DigestTransform.validate (C:\Users\NGrey\AppData\Local\Programs\Electron Update Test\resources\app.asar\node_modules\builder-util-runtime\out\httpExecutor.js:355:27)
    at WriteStream.<anonymous> (C:\Users\NGrey\AppData\Local\Programs\Electron Update Test\resources\app.asar\node_modules\electron-updater\out\differentialDownloader\DifferentialDownloader.js:133:41)
    at WriteStream.emit (events.js:315:20)
    at emitCloseNT (internal/streams/destroy.js:87:10)
    at processTicksAndRejections (internal/process/task_queues.js:79:21)
[2021-08-31 07:47:27.166] [info]  New version 0.0.2 has been downloaded to C:\Users\NGrey\AppData\Local\electron update test-updater\pending\update.exe
PUBLIC GITHUB REPO
[2021-08-31 07:57:41.365] [info]  Checking for update
[2021-08-31 07:57:42.525] [info]  Found version 0.0.2 (url: ElectronUpdateTestSetup.exe)
[2021-08-31 07:57:42.526] [info]  Downloading update from ElectronUpdateTestSetup.exe
[2021-08-31 07:57:42.527] [debug] updater cache dir: C:\Users\NGrey\AppData\Local\electron update test-updater
[2021-08-31 07:57:42.529] [info]  Download block maps (old: "https://github.com/ngrey5/electron-update-test/releases/download/v0.0.1/ElectronUpdateTestSetup.exe.blockmap", new: https://github.com/ngrey5/electron-update-test/releases/download/v0.0.2/ElectronUpdateTestSetup.exe.blockmap)
[2021-08-31 07:57:42.764] [info]  File has 35 changed blocks
[2021-08-31 07:57:42.764] [debug] [
  {
    "kind": 0,
    "start": 0,
    "end": 211730
  },
  {
    "kind": 1,
    "start": 211730,
    "end": 267833
  },
  {
    "kind": 0,
    "start": 267833,
    "end": 314319
  },
  {
    "kind": 1,
    "start": 314319,
    "end": 336887
  },
  {
    "kind": 0,
    "start": 336887,
    "end": 10484876
  },
  {
    "kind": 1,
    "start": 10484876,
    "end": 10909326
  },
  {
    "kind": 0,
    "start": 10909410,
    "end": 49629776
  },
  {
    "kind": 1,
    "start": 49629692,
    "end": 49645927
  },
  {
    "kind": 0,
    "start": 49646011,
    "end": 49672922
  },
  {
    "kind": 1,
    "start": 49672838,
    "end": 49782542
  },
  {
    "kind": 0,
    "start": 49782647,
    "end": 58935667
  },
  {
    "kind": 1,
    "start": 58935562,
    "end": 58976828
  },
  {
    "kind": 0,
    "start": 58976932,
    "end": 59201235
  },
  {
    "kind": 1,
    "start": 59201131,
    "end": 59210795
  },
  {
    "kind": 0,
    "start": 59210899,
    "end": 59270311
  },
  {
    "kind": 1,
    "start": 59270207,
    "end": 59381925
  }
]
[2021-08-31 07:57:42.774] [info]  Full: 57,990.16 KB, To download: 773.15 KB (1%)
[2021-08-31 07:57:42.777] [info]  Differential download: https://github.com/ngrey5/electron-update-test/releases/download/v0.0.2/ElectronUpdateTestSetup.exe
[2021-08-31 07:57:42.780] [debug] download range: bytes=211730-267832
[2021-08-31 07:57:43.073] [info]  Redirect to https://github-releases.githubusercontent.com/401702721/fa673fdd-8c19-46fb-a420-98ed779a59b0
[2021-08-31 07:57:43.137] [debug] download range: bytes=314319-336886
[2021-08-31 07:57:43.184] [debug] download range: bytes=10484876-10909325
[2021-08-31 07:57:43.396] [debug] download range: bytes=49629692-49645926
[2021-08-31 07:57:43.616] [debug] download range: bytes=49672838-49782541
[2021-08-31 07:57:43.663] [debug] download range: bytes=58935562-58976827
[2021-08-31 07:57:43.714] [debug] download range: bytes=59201131-59210794
[2021-08-31 07:57:43.721] [debug] download range: bytes=59270207-59381924
[2021-08-31 07:57:43.734] [info]  New version 0.0.2 has been downloaded to C:\Users\NGrey\AppData\Local\electron update test-updater\pending\ElectronUpdateTestSetup.exe

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NGrey5 I'm not sure I understand what this PR is solving. Is the current draft fixing private github downloads or did we discover a new issue (i.e. the new issue is checksum mismatch)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmaietta The PR is solving differential downloads with private github repos. Before it wouldn't download the proper files (blockmap.) With the changes currently made, it now downloads and compares the correct files. The checksum mismatch is an issue we now have after those changes have been made. It only happens with a private repo, so I would say it technically should be grouped together; but I could be wrong.


resolveFiles(updateInfo: PrivateGitHubUpdateInfo): Array<ResolvedUpdateFileInfo> {
return getFileList(updateInfo).map(it => {
const name = path.posix.basename(it.url).replace(/ /g, "-")
Expand All @@ -97,6 +117,10 @@ export class PrivateGitHubProvider extends BaseGitHubProvider<PrivateGitHubUpdat
return {
url: new URL(asset.url),
info: it,
updateFileUrls: {
new: updateInfo.assets.map(it => ({ name: it.name, url: new URL(it.url) })),
old: updateInfo.currentVersionAssets.map(it => ({ name: it.name, url: new URL(it.url) })),
},
}
})
}
Expand Down