electron-updater 6.8.8 → 6.8.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/AppImageUpdater.d.ts +2 -2
- package/out/AppImageUpdater.js.map +1 -1
- package/out/AppUpdater.d.ts +6 -2
- package/out/AppUpdater.js +32 -6
- package/out/AppUpdater.js.map +1 -1
- package/out/BaseUpdater.d.ts +2 -2
- package/out/BaseUpdater.js.map +1 -1
- package/out/DebUpdater.d.ts +2 -2
- package/out/DebUpdater.js.map +1 -1
- package/out/MacUpdater.d.ts +2 -2
- package/out/MacUpdater.js.map +1 -1
- package/out/NsisUpdater.d.ts +2 -2
- package/out/NsisUpdater.js.map +1 -1
- package/out/PacmanUpdater.d.ts +2 -2
- package/out/PacmanUpdater.js.map +1 -1
- package/out/RpmUpdater.d.ts +2 -2
- package/out/RpmUpdater.js.map +1 -1
- package/out/differentialDownloader/DataSplitter.d.ts +3 -2
- package/out/differentialDownloader/DataSplitter.js +36 -15
- package/out/differentialDownloader/DataSplitter.js.map +1 -1
- package/out/differentialDownloader/multipleRangeDownloader.js +22 -2
- package/out/differentialDownloader/multipleRangeDownloader.js.map +1 -1
- package/out/providers/GitLabProvider.d.ts +2 -0
- package/out/providers/GitLabProvider.js +5 -0
- package/out/providers/GitLabProvider.js.map +1 -1
- package/package.json +2 -2
package/out/MacUpdater.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AllPublishOptions } from "builder-util-runtime";
|
|
2
2
|
import { AppAdapter } from "./AppAdapter";
|
|
3
|
-
import { AppUpdater, DownloadUpdateOptions } from "./AppUpdater";
|
|
3
|
+
import { AppUpdater, DownloadExecutorResult, DownloadUpdateOptions } from "./AppUpdater";
|
|
4
4
|
import { ResolvedUpdateFileInfo } from "./main";
|
|
5
5
|
export declare class MacUpdater extends AppUpdater {
|
|
6
6
|
private readonly nativeUpdater;
|
|
@@ -13,7 +13,7 @@ export declare class MacUpdater extends AppUpdater {
|
|
|
13
13
|
protected static filterFilesForArch(files: ResolvedUpdateFileInfo[], isArm64Mac: boolean): ResolvedUpdateFileInfo[];
|
|
14
14
|
private debug;
|
|
15
15
|
private closeServerIfExists;
|
|
16
|
-
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<
|
|
16
|
+
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<DownloadExecutorResult>;
|
|
17
17
|
private updateDownloaded;
|
|
18
18
|
private handleUpdateDownloaded;
|
|
19
19
|
quitAndInstall(): void;
|
package/out/MacUpdater.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MacUpdater.js","sourceRoot":"","sources":["../src/MacUpdater.ts"],"names":[],"mappings":";;;AAAA,+DAAqF;AACrF,uCAAyD;AACzD,2BAAqC;AACrC,6BAA4B;AAC5B,+BAA4E;AAE5E,6CAAgE;AAGhE,mDAA+C;AAE/C,iDAA4C;AAC5C,mCAAoC;AAEpC,MAAa,UAAW,SAAQ,uBAAU;IAOxC,YAAY,OAA2B,EAAE,GAAgB;QACvD,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;QAPJ,kBAAa,GAAgB,OAAO,CAAC,UAAU,CAAC,CAAC,WAAW,CAAA;QAErE,6BAAwB,GAAG,KAAK,CAAA;QAOtC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE;YAClC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YACrB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;QACxB,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;YAC9C,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAA;YACpC,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAA;QAC/C,CAAC,CAAC,CAAA;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AAI,CAAC,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IAED,cAAc;QACZ,IAAI,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAClC,4DAA4D;YAC5D,IAAI,CAAC,sBAAsB,EAAE,CAAA;QAC/B,CAAC;aAAM,CAAC;YACN,sDAAsD;YACtD,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC,CAAA;YAE/E,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;gBAC/B;;;mBAGG;gBACH,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,CAAA;YACtC,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAlRD,gCAkRC","sourcesContent":["import { AllPublishOptions, newError, safeStringifyJson } from \"builder-util-runtime\"\nimport { pathExistsSync, stat, copyFile } from \"fs-extra\"\nimport { createReadStream } from \"fs\"\nimport * as path from \"path\"\nimport { createServer, IncomingMessage, Server, ServerResponse } from \"http\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { AppUpdater, DownloadUpdateOptions } from \"./AppUpdater\"\nimport { ResolvedUpdateFileInfo } from \"./main\"\nimport { UpdateDownloadedEvent } from \"./types\"\nimport { findFile } from \"./providers/Provider\"\nimport AutoUpdater = Electron.AutoUpdater\nimport { execFileSync } from \"child_process\"\nimport { randomBytes } from \"crypto\"\n\nexport class MacUpdater extends AppUpdater {\n private readonly nativeUpdater: AutoUpdater = require(\"electron\").autoUpdater\n\n private squirrelDownloadedUpdate = false\n\n private server?: Server\n\n constructor(options?: AllPublishOptions, app?: AppAdapter) {\n super(options, app)\n\n this.nativeUpdater.on(\"error\", it => {\n this._logger.warn(it)\n this.emit(\"error\", it)\n })\n this.nativeUpdater.on(\"update-downloaded\", () => {\n this.squirrelDownloadedUpdate = true\n this.debug(\"nativeUpdater.update-downloaded\")\n })\n }\n\n /** Filters update files to the appropriate architecture.\n * On arm64 Macs (including Rosetta), arm64 files are preferred when available.\n * On x64 Macs, arm64 files are excluded. */\n protected static filterFilesForArch(files: ResolvedUpdateFileInfo[], isArm64Mac: boolean): ResolvedUpdateFileInfo[] {\n const isArm64File = (file: ResolvedUpdateFileInfo) => file.url.pathname.includes(\"arm64\") || file.info.url?.includes(\"arm64\")\n if (isArm64Mac && files.some(isArm64File)) {\n return files.filter(file => isArm64Mac === isArm64File(file))\n }\n return files.filter(file => !isArm64File(file))\n }\n\n private debug(message: string): void {\n if (this._logger.debug != null) {\n this._logger.debug(message)\n }\n }\n\n private closeServerIfExists() {\n if (this.server) {\n this.debug(\"Closing proxy server\")\n this.server.close(err => {\n if (err) {\n this.debug(\"proxy server wasn't already open, probably attempted closing again as a safety check before quit\")\n }\n })\n }\n }\n\n protected async doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {\n let files = downloadUpdateOptions.updateInfoAndProvider.provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info)\n\n const log = this._logger\n\n // detect if we are running inside Rosetta emulation\n const sysctlRosettaInfoKey = \"sysctl.proc_translated\"\n let isRosetta = false\n try {\n this.debug(\"Checking for macOS Rosetta environment\")\n const result = execFileSync(\"sysctl\", [sysctlRosettaInfoKey], { encoding: \"utf8\" })\n isRosetta = result.includes(`${sysctlRosettaInfoKey}: 1`)\n log.info(`Checked for macOS Rosetta environment (isRosetta=${isRosetta})`)\n } catch (e: any) {\n log.warn(`sysctl shell command to check for macOS Rosetta environment failed: ${e}`)\n }\n\n let isArm64Mac = false\n try {\n this.debug(\"Checking for arm64 in uname\")\n const result = execFileSync(\"uname\", [\"-a\"], { encoding: \"utf8\" })\n const isArm = result.includes(\"ARM\")\n log.info(`Checked 'uname -a': arm64=${isArm}`)\n isArm64Mac = isArm64Mac || isArm\n } catch (e: any) {\n log.warn(`uname shell command to check for arm64 failed: ${e}`)\n }\n\n isArm64Mac = isArm64Mac || process.arch === \"arm64\" || isRosetta\n\n // allow arm64 macs to install universal or rosetta2(x64) - https://github.com/electron-userland/electron-builder/pull/5524\n files = MacUpdater.filterFilesForArch(files, isArm64Mac)\n\n const zipFileInfo = findFile(files, \"zip\", [\"pkg\", \"dmg\"])\n\n if (zipFileInfo == null) {\n throw newError(`ZIP file not provided: ${safeStringifyJson(files)}`, \"ERR_UPDATER_ZIP_FILE_NOT_FOUND\")\n }\n\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const CURRENT_MAC_APP_ZIP_FILE_NAME = \"update.zip\"\n\n return this.executeDownload({\n fileExtension: \"zip\",\n fileInfo: zipFileInfo,\n downloadUpdateOptions,\n task: async (destinationFile, downloadOptions) => {\n const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)\n const canDifferentialDownload = () => {\n if (!pathExistsSync(cachedUpdateFilePath)) {\n log.info(\"Unable to locate previous update.zip for differential download (is this first install?), falling back to full download\")\n return false\n }\n return !downloadUpdateOptions.disableDifferentialDownload\n }\n let differentialDownloadFailed = true\n if (canDifferentialDownload()) {\n differentialDownloadFailed = await this.differentialDownloadInstaller(zipFileInfo, downloadUpdateOptions, destinationFile, provider, CURRENT_MAC_APP_ZIP_FILE_NAME)\n }\n\n if (differentialDownloadFailed) {\n await this.httpExecutor.download(zipFileInfo.url, destinationFile, downloadOptions)\n }\n },\n done: async event => {\n if (!downloadUpdateOptions.disableDifferentialDownload) {\n try {\n const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)\n await copyFile(event.downloadedFile, cachedUpdateFilePath)\n } catch (error: any) {\n this._logger.warn(`Unable to copy file for caching for future differential downloads: ${error.message}`)\n }\n }\n return this.updateDownloaded(zipFileInfo, event)\n },\n })\n }\n\n private async updateDownloaded(zipFileInfo: ResolvedUpdateFileInfo, event: UpdateDownloadedEvent): Promise<Array<string>> {\n const downloadedFile = event.downloadedFile\n const updateFileSize = zipFileInfo.info.size ?? (await stat(downloadedFile)).size\n\n const log = this._logger\n const logContext = `fileToProxy=${zipFileInfo.url.href}`\n this.closeServerIfExists()\n this.debug(`Creating proxy server for native Squirrel.Mac (${logContext})`)\n this.server = createServer()\n this.debug(`Proxy server for native Squirrel.Mac is created (${logContext})`)\n this.server.on(\"close\", () => {\n log.info(`Proxy server for native Squirrel.Mac is closed (${logContext})`)\n })\n\n // must be called after server is listening, otherwise address is null\n const getServerUrl = (s: Server): string => {\n const address = s.address()\n if (typeof address === \"string\") {\n return address\n }\n return `http://127.0.0.1:${address?.port}`\n }\n\n return await new Promise<Array<string>>((resolve, reject) => {\n const pass = randomBytes(64).toString(\"base64\").replace(/\\//g, \"_\").replace(/\\+/g, \"-\")\n const authInfo = Buffer.from(`autoupdater:${pass}`, \"ascii\")\n\n // insecure random is ok\n const fileUrl = `/${randomBytes(64).toString(\"hex\")}.zip`\n this.server!.on(\"request\", (request: IncomingMessage, response: ServerResponse) => {\n const requestUrl = request.url!\n log.info(`${requestUrl} requested`)\n if (requestUrl === \"/\") {\n // check for basic auth header\n if (!request.headers.authorization || request.headers.authorization.indexOf(\"Basic \") === -1) {\n response.statusCode = 401\n response.statusMessage = \"Invalid Authentication Credentials\"\n response.end()\n log.warn(\"No authenthication info\")\n return\n }\n\n // verify auth credentials\n const base64Credentials = request.headers.authorization.split(\" \")[1]\n const credentials = Buffer.from(base64Credentials, \"base64\").toString(\"ascii\")\n const [username, password] = credentials.split(\":\")\n if (username !== \"autoupdater\" || password !== pass) {\n response.statusCode = 401\n response.statusMessage = \"Invalid Authentication Credentials\"\n response.end()\n log.warn(\"Invalid authenthication credentials\")\n return\n }\n\n const data = Buffer.from(`{ \"url\": \"${getServerUrl(this.server!)}${fileUrl}\" }`)\n response.writeHead(200, { \"Content-Type\": \"application/json\", \"Content-Length\": data.length })\n response.end(data)\n return\n }\n\n if (!requestUrl.startsWith(fileUrl)) {\n log.warn(`${requestUrl} requested, but not supported`)\n response.writeHead(404)\n response.end()\n return\n }\n\n log.info(`${fileUrl} requested by Squirrel.Mac, pipe ${downloadedFile}`)\n\n let errorOccurred = false\n response.on(\"finish\", () => {\n if (!errorOccurred) {\n this.nativeUpdater.removeListener(\"error\", reject)\n resolve([])\n }\n })\n\n const readStream = createReadStream(downloadedFile)\n readStream.on(\"error\", error => {\n try {\n response.end()\n } catch (e: any) {\n log.warn(`cannot end response: ${e}`)\n }\n errorOccurred = true\n this.nativeUpdater.removeListener(\"error\", reject)\n reject(new Error(`Cannot pipe \"${downloadedFile}\": ${error}`))\n })\n\n response.writeHead(200, {\n \"Content-Type\": \"application/zip\",\n \"Content-Length\": updateFileSize,\n })\n readStream.pipe(response)\n })\n\n this.debug(`Proxy server for native Squirrel.Mac is starting to listen (${logContext})`)\n\n this.server!.listen(0, \"127.0.0.1\", () => {\n this.debug(`Proxy server for native Squirrel.Mac is listening (address=${getServerUrl(this.server!)}, ${logContext})`)\n this.nativeUpdater.setFeedURL({\n url: getServerUrl(this.server!),\n headers: {\n \"Cache-Control\": \"no-cache\",\n Authorization: `Basic ${authInfo.toString(\"base64\")}`,\n },\n })\n\n // The update has been downloaded and is ready to be served to Squirrel\n this.dispatchUpdateDownloaded(event)\n\n if (this.autoInstallOnAppQuit) {\n this.nativeUpdater.once(\"error\", reject)\n // This will trigger fetching and installing the file on Squirrel side\n this.nativeUpdater.checkForUpdates()\n } else {\n resolve([])\n }\n })\n })\n }\n\n private handleUpdateDownloaded() {\n if (this.autoRunAppAfterInstall) {\n this.nativeUpdater.quitAndInstall()\n } else {\n this.app.quit()\n }\n this.closeServerIfExists()\n }\n\n quitAndInstall(): void {\n if (this.squirrelDownloadedUpdate) {\n // update already fetched by Squirrel, it's ready to install\n this.handleUpdateDownloaded()\n } else {\n // Quit and install as soon as Squirrel get the update\n this.nativeUpdater.on(\"update-downloaded\", () => this.handleUpdateDownloaded())\n\n if (!this.autoInstallOnAppQuit) {\n /**\n * If this was not `true` previously then MacUpdater.doDownloadUpdate()\n * would not actually initiate the downloading by electron's autoUpdater\n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AE,CAAC;gBAC/B;;;mBAGG;gBACH,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,CAAA;YACtC,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAlRD,gCAkRC","sourcesContent":["import { AllPublishOptions, newError, safeStringifyJson } from \"builder-util-runtime\"\nimport { pathExistsSync, stat, copyFile } from \"fs-extra\"\nimport { createReadStream } from \"fs\"\nimport * as path from \"path\"\nimport { createServer, IncomingMessage, Server, ServerResponse } from \"http\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { AppUpdater, DownloadExecutorResult, DownloadUpdateOptions } from \"./AppUpdater\"\nimport { ResolvedUpdateFileInfo } from \"./main\"\nimport { UpdateDownloadedEvent } from \"./types\"\nimport { findFile } from \"./providers/Provider\"\nimport AutoUpdater = Electron.AutoUpdater\nimport { execFileSync } from \"child_process\"\nimport { randomBytes } from \"crypto\"\n\nexport class MacUpdater extends AppUpdater {\n private readonly nativeUpdater: AutoUpdater = require(\"electron\").autoUpdater\n\n private squirrelDownloadedUpdate = false\n\n private server?: Server\n\n constructor(options?: AllPublishOptions, app?: AppAdapter) {\n super(options, app)\n\n this.nativeUpdater.on(\"error\", it => {\n this._logger.warn(it)\n this.emit(\"error\", it)\n })\n this.nativeUpdater.on(\"update-downloaded\", () => {\n this.squirrelDownloadedUpdate = true\n this.debug(\"nativeUpdater.update-downloaded\")\n })\n }\n\n /** Filters update files to the appropriate architecture.\n * On arm64 Macs (including Rosetta), arm64 files are preferred when available.\n * On x64 Macs, arm64 files are excluded. */\n protected static filterFilesForArch(files: ResolvedUpdateFileInfo[], isArm64Mac: boolean): ResolvedUpdateFileInfo[] {\n const isArm64File = (file: ResolvedUpdateFileInfo) => file.url.pathname.includes(\"arm64\") || file.info.url?.includes(\"arm64\")\n if (isArm64Mac && files.some(isArm64File)) {\n return files.filter(file => isArm64Mac === isArm64File(file))\n }\n return files.filter(file => !isArm64File(file))\n }\n\n private debug(message: string): void {\n if (this._logger.debug != null) {\n this._logger.debug(message)\n }\n }\n\n private closeServerIfExists() {\n if (this.server) {\n this.debug(\"Closing proxy server\")\n this.server.close(err => {\n if (err) {\n this.debug(\"proxy server wasn't already open, probably attempted closing again as a safety check before quit\")\n }\n })\n }\n }\n\n protected async doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<DownloadExecutorResult> {\n let files = downloadUpdateOptions.updateInfoAndProvider.provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info)\n\n const log = this._logger\n\n // detect if we are running inside Rosetta emulation\n const sysctlRosettaInfoKey = \"sysctl.proc_translated\"\n let isRosetta = false\n try {\n this.debug(\"Checking for macOS Rosetta environment\")\n const result = execFileSync(\"sysctl\", [sysctlRosettaInfoKey], { encoding: \"utf8\" })\n isRosetta = result.includes(`${sysctlRosettaInfoKey}: 1`)\n log.info(`Checked for macOS Rosetta environment (isRosetta=${isRosetta})`)\n } catch (e: any) {\n log.warn(`sysctl shell command to check for macOS Rosetta environment failed: ${e}`)\n }\n\n let isArm64Mac = false\n try {\n this.debug(\"Checking for arm64 in uname\")\n const result = execFileSync(\"uname\", [\"-a\"], { encoding: \"utf8\" })\n const isArm = result.includes(\"ARM\")\n log.info(`Checked 'uname -a': arm64=${isArm}`)\n isArm64Mac = isArm64Mac || isArm\n } catch (e: any) {\n log.warn(`uname shell command to check for arm64 failed: ${e}`)\n }\n\n isArm64Mac = isArm64Mac || process.arch === \"arm64\" || isRosetta\n\n // allow arm64 macs to install universal or rosetta2(x64) - https://github.com/electron-userland/electron-builder/pull/5524\n files = MacUpdater.filterFilesForArch(files, isArm64Mac)\n\n const zipFileInfo = findFile(files, \"zip\", [\"pkg\", \"dmg\"])\n\n if (zipFileInfo == null) {\n throw newError(`ZIP file not provided: ${safeStringifyJson(files)}`, \"ERR_UPDATER_ZIP_FILE_NOT_FOUND\")\n }\n\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const CURRENT_MAC_APP_ZIP_FILE_NAME = \"update.zip\"\n\n return this.executeDownload({\n fileExtension: \"zip\",\n fileInfo: zipFileInfo,\n downloadUpdateOptions,\n task: async (destinationFile, downloadOptions) => {\n const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)\n const canDifferentialDownload = () => {\n if (!pathExistsSync(cachedUpdateFilePath)) {\n log.info(\"Unable to locate previous update.zip for differential download (is this first install?), falling back to full download\")\n return false\n }\n return !downloadUpdateOptions.disableDifferentialDownload\n }\n let differentialDownloadFailed = true\n if (canDifferentialDownload()) {\n differentialDownloadFailed = await this.differentialDownloadInstaller(zipFileInfo, downloadUpdateOptions, destinationFile, provider, CURRENT_MAC_APP_ZIP_FILE_NAME)\n }\n\n if (differentialDownloadFailed) {\n await this.httpExecutor.download(zipFileInfo.url, destinationFile, downloadOptions)\n }\n },\n done: async event => {\n if (!downloadUpdateOptions.disableDifferentialDownload) {\n try {\n const cachedUpdateFilePath = path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_MAC_APP_ZIP_FILE_NAME)\n await copyFile(event.downloadedFile, cachedUpdateFilePath)\n } catch (error: any) {\n this._logger.warn(`Unable to copy file for caching for future differential downloads: ${error.message}`)\n }\n }\n return this.updateDownloaded(zipFileInfo, event)\n },\n })\n }\n\n private async updateDownloaded(zipFileInfo: ResolvedUpdateFileInfo, event: UpdateDownloadedEvent): Promise<Array<string>> {\n const downloadedFile = event.downloadedFile\n const updateFileSize = zipFileInfo.info.size ?? (await stat(downloadedFile)).size\n\n const log = this._logger\n const logContext = `fileToProxy=${zipFileInfo.url.href}`\n this.closeServerIfExists()\n this.debug(`Creating proxy server for native Squirrel.Mac (${logContext})`)\n this.server = createServer()\n this.debug(`Proxy server for native Squirrel.Mac is created (${logContext})`)\n this.server.on(\"close\", () => {\n log.info(`Proxy server for native Squirrel.Mac is closed (${logContext})`)\n })\n\n // must be called after server is listening, otherwise address is null\n const getServerUrl = (s: Server): string => {\n const address = s.address()\n if (typeof address === \"string\") {\n return address\n }\n return `http://127.0.0.1:${address?.port}`\n }\n\n return await new Promise<Array<string>>((resolve, reject) => {\n const pass = randomBytes(64).toString(\"base64\").replace(/\\//g, \"_\").replace(/\\+/g, \"-\")\n const authInfo = Buffer.from(`autoupdater:${pass}`, \"ascii\")\n\n // insecure random is ok\n const fileUrl = `/${randomBytes(64).toString(\"hex\")}.zip`\n this.server!.on(\"request\", (request: IncomingMessage, response: ServerResponse) => {\n const requestUrl = request.url!\n log.info(`${requestUrl} requested`)\n if (requestUrl === \"/\") {\n // check for basic auth header\n if (!request.headers.authorization || request.headers.authorization.indexOf(\"Basic \") === -1) {\n response.statusCode = 401\n response.statusMessage = \"Invalid Authentication Credentials\"\n response.end()\n log.warn(\"No authenthication info\")\n return\n }\n\n // verify auth credentials\n const base64Credentials = request.headers.authorization.split(\" \")[1]\n const credentials = Buffer.from(base64Credentials, \"base64\").toString(\"ascii\")\n const [username, password] = credentials.split(\":\")\n if (username !== \"autoupdater\" || password !== pass) {\n response.statusCode = 401\n response.statusMessage = \"Invalid Authentication Credentials\"\n response.end()\n log.warn(\"Invalid authenthication credentials\")\n return\n }\n\n const data = Buffer.from(`{ \"url\": \"${getServerUrl(this.server!)}${fileUrl}\" }`)\n response.writeHead(200, { \"Content-Type\": \"application/json\", \"Content-Length\": data.length })\n response.end(data)\n return\n }\n\n if (!requestUrl.startsWith(fileUrl)) {\n log.warn(`${requestUrl} requested, but not supported`)\n response.writeHead(404)\n response.end()\n return\n }\n\n log.info(`${fileUrl} requested by Squirrel.Mac, pipe ${downloadedFile}`)\n\n let errorOccurred = false\n response.on(\"finish\", () => {\n if (!errorOccurred) {\n this.nativeUpdater.removeListener(\"error\", reject)\n resolve([])\n }\n })\n\n const readStream = createReadStream(downloadedFile)\n readStream.on(\"error\", error => {\n try {\n response.end()\n } catch (e: any) {\n log.warn(`cannot end response: ${e}`)\n }\n errorOccurred = true\n this.nativeUpdater.removeListener(\"error\", reject)\n reject(new Error(`Cannot pipe \"${downloadedFile}\": ${error}`))\n })\n\n response.writeHead(200, {\n \"Content-Type\": \"application/zip\",\n \"Content-Length\": updateFileSize,\n })\n readStream.pipe(response)\n })\n\n this.debug(`Proxy server for native Squirrel.Mac is starting to listen (${logContext})`)\n\n this.server!.listen(0, \"127.0.0.1\", () => {\n this.debug(`Proxy server for native Squirrel.Mac is listening (address=${getServerUrl(this.server!)}, ${logContext})`)\n this.nativeUpdater.setFeedURL({\n url: getServerUrl(this.server!),\n headers: {\n \"Cache-Control\": \"no-cache\",\n Authorization: `Basic ${authInfo.toString(\"base64\")}`,\n },\n })\n\n // The update has been downloaded and is ready to be served to Squirrel\n this.dispatchUpdateDownloaded(event)\n\n if (this.autoInstallOnAppQuit) {\n this.nativeUpdater.once(\"error\", reject)\n // This will trigger fetching and installing the file on Squirrel side\n this.nativeUpdater.checkForUpdates()\n } else {\n resolve([])\n }\n })\n })\n }\n\n private handleUpdateDownloaded() {\n if (this.autoRunAppAfterInstall) {\n this.nativeUpdater.quitAndInstall()\n } else {\n this.app.quit()\n }\n this.closeServerIfExists()\n }\n\n quitAndInstall(): void {\n if (this.squirrelDownloadedUpdate) {\n // update already fetched by Squirrel, it's ready to install\n this.handleUpdateDownloaded()\n } else {\n // Quit and install as soon as Squirrel get the update\n this.nativeUpdater.on(\"update-downloaded\", () => this.handleUpdateDownloaded())\n\n if (!this.autoInstallOnAppQuit) {\n /**\n * If this was not `true` previously then MacUpdater.doDownloadUpdate()\n * would not actually initiate the downloading by electron's autoUpdater\n */\n this.nativeUpdater.checkForUpdates()\n }\n }\n }\n}\n"]}
|
package/out/NsisUpdater.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AllPublishOptions } from "builder-util-runtime";
|
|
2
2
|
import { AppAdapter } from "./AppAdapter";
|
|
3
|
-
import { DownloadUpdateOptions } from "./AppUpdater";
|
|
3
|
+
import { DownloadExecutorResult, DownloadUpdateOptions } from "./AppUpdater";
|
|
4
4
|
import { BaseUpdater, InstallOptions } from "./BaseUpdater";
|
|
5
5
|
import { VerifyUpdateCodeSignature } from "./main";
|
|
6
6
|
export declare class NsisUpdater extends BaseUpdater {
|
|
@@ -18,7 +18,7 @@ export declare class NsisUpdater extends BaseUpdater {
|
|
|
18
18
|
get verifyUpdateCodeSignature(): VerifyUpdateCodeSignature;
|
|
19
19
|
set verifyUpdateCodeSignature(value: VerifyUpdateCodeSignature);
|
|
20
20
|
/*** @private */
|
|
21
|
-
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<
|
|
21
|
+
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<DownloadExecutorResult>;
|
|
22
22
|
private verifySignature;
|
|
23
23
|
protected doInstall(options: InstallOptions): boolean;
|
|
24
24
|
private differentialDownloadWebPackage;
|
package/out/NsisUpdater.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NsisUpdater.js","sourceRoot":"","sources":["../src/NsisUpdater.ts"],"names":[],"mappings":";;;AAAA,+DAAmJ;AACnJ,6BAA4B;AAG5B,+CAA2D;AAE3D,4IAAwI;AACxI,mCAA2C;AAE3C,mDAAyD;AACzD,uCAAiC;AACjC,qGAA0E;AAC1E,6BAAyB;AAEzB,MAAa,WAAY,SAAQ,yBAAW;IAO1C,YAAY,OAAkC,EAAE,GAAgB;QAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;QAGX,+BAA0B,GAA8B,CAAC,cAA6B,EAAE,uBAA+B,EAAE,EAAE,CACnI,IAAA,wDAAe,EAAC,cAAc,EAAE,uBAAuB,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IAHxE,CAAC;IAKD;;;OAGG;IACH,IAAI,yBAAyB;QAC3B,OAAO,IAAI,CAAC,0BAA0B,CAAA;IACxC,CAAC;IAED,IAAI,yBAAyB,CAAC,KAAgC;QAC5D,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,0BAA0B,GAAG,KAAK,CAAA;QACzC,CAAC;IACH,CAAC;IA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LER_FILE_NAME, CURRENT_APP_PACKAGE_FILE_NAME } from \"builder-util-runtime\"\nimport * as path from \"path\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { DownloadUpdateOptions } from \"./AppUpdater\"\nimport { BaseUpdater, InstallOptions } from \"./BaseUpdater\"\nimport { DifferentialDownloaderOptions } from \"./differentialDownloader/DifferentialDownloader\"\nimport { FileWithEmbeddedBlockMapDifferentialDownloader } from \"./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader\"\nimport { DOWNLOAD_PROGRESS } from \"./types\"\nimport { VerifyUpdateCodeSignature } from \"./main\"\nimport { findFile, Provider } from \"./providers/Provider\"\nimport { unlink } from \"fs-extra\"\nimport { verifySignature } from \"./windowsExecutableCodeSignatureVerifier\"\nimport { URL } from \"url\"\n\nexport class NsisUpdater extends BaseUpdater {\n /**\n * Specify custom install directory path\n *\n */\n installDirectory?: string\n\n constructor(options?: AllPublishOptions | null, app?: AppAdapter) {\n super(options, app)\n }\n\n protected _verifyUpdateCodeSignature: VerifyUpdateCodeSignature = (publisherNames: Array<string>, unescapedTempUpdateFile: string) =>\n verifySignature(publisherNames, unescapedTempUpdateFile, this._logger)\n\n /**\n * The verifyUpdateCodeSignature. You can pass [win-verify-signature](https://github.com/beyondkmp/win-verify-trust) or another custom verify function: ` (publisherName: string[], path: string) => Promise<string | null>`.\n * The default verify function uses [windowsExecutableCodeSignatureVerifier](https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts)\n */\n get verifyUpdateCodeSignature(): VerifyUpdateCodeSignature {\n return this._verifyUpdateCodeSignature\n }\n\n set verifyUpdateCodeSignature(value: VerifyUpdateCodeSignature) {\n if (value) {\n this._verifyUpdateCodeSignature = value\n }\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>> {\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), \"exe\")!\n return this.executeDownload({\n fileExtension: \"exe\",\n downloadUpdateOptions,\n fileInfo,\n task: async (destinationFile, downloadOptions, packageFile, removeTempDirIfAny) => {\n const packageInfo = fileInfo.packageInfo\n const isWebInstaller = packageInfo != null && packageFile != null\n if (isWebInstaller && downloadUpdateOptions.disableWebInstaller) {\n throw newError(\n `Unable to download new version ${downloadUpdateOptions.updateInfoAndProvider.info.version}. Web Installers are disabled`,\n \"ERR_UPDATER_WEB_INSTALLER_DISABLED\"\n )\n }\n if (!isWebInstaller && !downloadUpdateOptions.disableWebInstaller) {\n this._logger.warn(\n \"disableWebInstaller is set to false, you should set it to true if you do not plan on using a web installer. This will default to true in a future version.\"\n )\n }\n if (\n isWebInstaller ||\n downloadUpdateOptions.disableDifferentialDownload ||\n (await this.differentialDownloadInstaller(fileInfo, downloadUpdateOptions, destinationFile, provider, CURRENT_APP_INSTALLER_FILE_NAME))\n ) {\n await this.httpExecutor.download(fileInfo.url, destinationFile, downloadOptions)\n }\n\n const signatureVerificationStatus = await this.verifySignature(destinationFile)\n if (signatureVerificationStatus != null) {\n await removeTempDirIfAny()\n // noinspection ThrowInsideFinallyBlockJS\n throw newError(\n `New version ${downloadUpdateOptions.updateInfoAndProvider.info.version} is not signed by the application owner: ${signatureVerificationStatus}`,\n \"ERR_UPDATER_INVALID_SIGNATURE\"\n )\n }\n\n if (isWebInstaller) {\n if (await this.differentialDownloadWebPackage(downloadUpdateOptions, packageInfo, packageFile, provider)) {\n try {\n await this.httpExecutor.download(new URL(packageInfo.path), packageFile, {\n headers: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n sha512: packageInfo.sha512,\n })\n } catch (e: any) {\n try {\n await unlink(packageFile)\n } catch (_ignored) {\n // ignore\n }\n\n throw e\n }\n }\n }\n },\n })\n }\n\n // $certificateInfo = (Get-AuthenticodeSignature 'xxx\\yyy.exe'\n // | where {$_.Status.Equals([System.Management.Automation.SignatureStatus]::Valid) -and $_.SignerCertificate.Subject.Contains(\"CN=siemens.com\")})\n // | Out-String ; if ($certificateInfo) { exit 0 } else { exit 1 }\n private async verifySignature(tempUpdateFile: string): Promise<string | null> {\n let publisherName: Array<string> | string | null\n try {\n publisherName = (await this.configOnDisk.value).publisherName\n if (publisherName == null) {\n return null\n }\n } catch (e: any) {\n if (e.code === \"ENOENT\") {\n // no app-update.yml\n return null\n }\n throw e\n }\n return await this._verifyUpdateCodeSignature(Array.isArray(publisherName) ? publisherName : [publisherName], tempUpdateFile)\n }\n\n protected doInstall(options: InstallOptions): boolean {\n const installerPath = this.installerPath\n if (installerPath == null) {\n this.dispatchError(new Error(\"No update filepath provided, can't quit and install\"))\n return false\n }\n\n const args = [\"--updated\"]\n if (options.isSilent) {\n args.push(\"/S\")\n }\n\n if (options.isForceRunAfter) {\n args.push(\"--force-run\")\n }\n\n if (this.installDirectory) {\n // maybe check if folder exists\n args.push(`/D=${this.installDirectory}`)\n }\n\n const packagePath = this.downloadedUpdateHelper == null ? null : this.downloadedUpdateHelper.packageFile\n if (packagePath != null) {\n // only = form is supported\n args.push(`--package-file=${packagePath}`)\n }\n\n const callUsingElevation = (): void => {\n this.spawnLog(path.join(process.resourcesPath, \"elevate.exe\"), [installerPath].concat(args)).catch(e => this.dispatchError(e))\n }\n\n if (options.isAdminRightsRequired) {\n this._logger.info(\"isAdminRightsRequired is set to true, run installer using elevate.exe\")\n callUsingElevation()\n return true\n }\n\n this.spawnLog(installerPath, args).catch((e: Error) => {\n // https://github.com/electron-userland/electron-builder/issues/1129\n // Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors\n const errorCode = (e as NodeJS.ErrnoException).code\n this._logger.info(\n `Cannot run installer: error code: ${errorCode}, error message: \"${e.message}\", will be executed again using elevate if EACCES, and will try to use electron.shell.openItem if ENOENT`\n )\n if (errorCode === \"UNKNOWN\" || errorCode === \"EACCES\") {\n callUsingElevation()\n } else if (errorCode === \"ENOENT\") {\n require(\"electron\")\n .shell.openPath(installerPath)\n .catch((err: Error) => this.dispatchError(err))\n } else {\n this.dispatchError(e)\n }\n })\n return true\n }\n\n private async differentialDownloadWebPackage(\n downloadUpdateOptions: DownloadUpdateOptions,\n packageInfo: PackageFileInfo,\n packagePath: string,\n provider: Provider<any>\n ): Promise<boolean> {\n if (packageInfo.blockMapSize == null) {\n return true\n }\n\n try {\n const downloadOptions: DifferentialDownloaderOptions = {\n newUrl: new URL(packageInfo.path),\n oldFile: path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_APP_PACKAGE_FILE_NAME),\n logger: this._logger,\n newFile: packagePath,\n requestHeaders: this.requestHeaders,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n }\n\n if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {\n downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it)\n }\n\n await new FileWithEmbeddedBlockMapDifferentialDownloader(packageInfo, this.httpExecutor, downloadOptions).download()\n } catch (e: any) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n // during test (developer machine mac or linux) we must throw error\n return process.platform === \"win32\"\n }\n return false\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NsisUpdater.js","sourceRoot":"","sources":["../src/NsisUpdater.ts"],"names":[],"mappings":";;;AAAA,+DAAmJ;AACnJ,6BAA4B;AAG5B,+CAA2D;AAE3D,4IAAwI;AACxI,mCAA2C;AAE3C,mDAAyD;AACzD,uCAAiC;AACjC,qGAA0E;AAC1E,6BAAyB;AAEzB,MAAa,WAAY,SAAQ,yBAAW;IAO1C,YAAY,OAAkC,EAAE,GAAgB;QAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;QAGX,+BAA0B,GAA8B,CAAC,cAA6B,EAAE,uBAA+B,EAAE,EAAE,CACnI,IAAA,wDAAe,EAAC,cAAc,EAAE,uBAAuB,EAAE,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AO,CAAC,KAAK,CAAC,8DAA8D,CAAC,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC,CAAA;YAChG,mEAAmE;YACnE,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAA;QACrC,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAzMD,kCAyMC","sourcesContent":["import { AllPublishOptions, newError, PackageFileInfo, CURRENT_APP_INSTALLER_FILE_NAME, CURRENT_APP_PACKAGE_FILE_NAME } from \"builder-util-runtime\"\nimport * as path from \"path\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { DownloadExecutorResult, DownloadUpdateOptions } from \"./AppUpdater\"\nimport { BaseUpdater, InstallOptions } from \"./BaseUpdater\"\nimport { DifferentialDownloaderOptions } from \"./differentialDownloader/DifferentialDownloader\"\nimport { FileWithEmbeddedBlockMapDifferentialDownloader } from \"./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader\"\nimport { DOWNLOAD_PROGRESS } from \"./types\"\nimport { VerifyUpdateCodeSignature } from \"./main\"\nimport { findFile, Provider } from \"./providers/Provider\"\nimport { unlink } from \"fs-extra\"\nimport { verifySignature } from \"./windowsExecutableCodeSignatureVerifier\"\nimport { URL } from \"url\"\n\nexport class NsisUpdater extends BaseUpdater {\n /**\n * Specify custom install directory path\n *\n */\n installDirectory?: string\n\n constructor(options?: AllPublishOptions | null, app?: AppAdapter) {\n super(options, app)\n }\n\n protected _verifyUpdateCodeSignature: VerifyUpdateCodeSignature = (publisherNames: Array<string>, unescapedTempUpdateFile: string) =>\n verifySignature(publisherNames, unescapedTempUpdateFile, this._logger)\n\n /**\n * The verifyUpdateCodeSignature. You can pass [win-verify-signature](https://github.com/beyondkmp/win-verify-trust) or another custom verify function: ` (publisherName: string[], path: string) => Promise<string | null>`.\n * The default verify function uses [windowsExecutableCodeSignatureVerifier](https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/windowsExecutableCodeSignatureVerifier.ts)\n */\n get verifyUpdateCodeSignature(): VerifyUpdateCodeSignature {\n return this._verifyUpdateCodeSignature\n }\n\n set verifyUpdateCodeSignature(value: VerifyUpdateCodeSignature) {\n if (value) {\n this._verifyUpdateCodeSignature = value\n }\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<DownloadExecutorResult> {\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), \"exe\")!\n return this.executeDownload({\n fileExtension: \"exe\",\n downloadUpdateOptions,\n fileInfo,\n task: async (destinationFile, downloadOptions, packageFile, removeTempDirIfAny) => {\n const packageInfo = fileInfo.packageInfo\n const isWebInstaller = packageInfo != null && packageFile != null\n if (isWebInstaller && downloadUpdateOptions.disableWebInstaller) {\n throw newError(\n `Unable to download new version ${downloadUpdateOptions.updateInfoAndProvider.info.version}. Web Installers are disabled`,\n \"ERR_UPDATER_WEB_INSTALLER_DISABLED\"\n )\n }\n if (!isWebInstaller && !downloadUpdateOptions.disableWebInstaller) {\n this._logger.warn(\n \"disableWebInstaller is set to false, you should set it to true if you do not plan on using a web installer. This will default to true in a future version.\"\n )\n }\n if (\n isWebInstaller ||\n downloadUpdateOptions.disableDifferentialDownload ||\n (await this.differentialDownloadInstaller(fileInfo, downloadUpdateOptions, destinationFile, provider, CURRENT_APP_INSTALLER_FILE_NAME))\n ) {\n await this.httpExecutor.download(fileInfo.url, destinationFile, downloadOptions)\n }\n\n const signatureVerificationStatus = await this.verifySignature(destinationFile)\n if (signatureVerificationStatus != null) {\n await removeTempDirIfAny()\n // noinspection ThrowInsideFinallyBlockJS\n throw newError(\n `New version ${downloadUpdateOptions.updateInfoAndProvider.info.version} is not signed by the application owner: ${signatureVerificationStatus}`,\n \"ERR_UPDATER_INVALID_SIGNATURE\"\n )\n }\n\n if (isWebInstaller) {\n if (await this.differentialDownloadWebPackage(downloadUpdateOptions, packageInfo, packageFile, provider)) {\n try {\n await this.httpExecutor.download(new URL(packageInfo.path), packageFile, {\n headers: downloadUpdateOptions.requestHeaders,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n sha512: packageInfo.sha512,\n })\n } catch (e: any) {\n try {\n await unlink(packageFile)\n } catch (_ignored) {\n // ignore\n }\n\n throw e\n }\n }\n }\n },\n })\n }\n\n // $certificateInfo = (Get-AuthenticodeSignature 'xxx\\yyy.exe'\n // | where {$_.Status.Equals([System.Management.Automation.SignatureStatus]::Valid) -and $_.SignerCertificate.Subject.Contains(\"CN=siemens.com\")})\n // | Out-String ; if ($certificateInfo) { exit 0 } else { exit 1 }\n private async verifySignature(tempUpdateFile: string): Promise<string | null> {\n let publisherName: Array<string> | string | null\n try {\n publisherName = (await this.configOnDisk.value).publisherName\n if (publisherName == null) {\n return null\n }\n } catch (e: any) {\n if (e.code === \"ENOENT\") {\n // no app-update.yml\n return null\n }\n throw e\n }\n return await this._verifyUpdateCodeSignature(Array.isArray(publisherName) ? publisherName : [publisherName], tempUpdateFile)\n }\n\n protected doInstall(options: InstallOptions): boolean {\n const installerPath = this.installerPath\n if (installerPath == null) {\n this.dispatchError(new Error(\"No update filepath provided, can't quit and install\"))\n return false\n }\n\n const args = [\"--updated\"]\n if (options.isSilent) {\n args.push(\"/S\")\n }\n\n if (options.isForceRunAfter) {\n args.push(\"--force-run\")\n }\n\n if (this.installDirectory) {\n // maybe check if folder exists\n args.push(`/D=${this.installDirectory}`)\n }\n\n const packagePath = this.downloadedUpdateHelper == null ? null : this.downloadedUpdateHelper.packageFile\n if (packagePath != null) {\n // only = form is supported\n args.push(`--package-file=${packagePath}`)\n }\n\n const callUsingElevation = (): void => {\n this.spawnLog(path.join(process.resourcesPath, \"elevate.exe\"), [installerPath].concat(args)).catch(e => this.dispatchError(e))\n }\n\n if (options.isAdminRightsRequired) {\n this._logger.info(\"isAdminRightsRequired is set to true, run installer using elevate.exe\")\n callUsingElevation()\n return true\n }\n\n this.spawnLog(installerPath, args).catch((e: Error) => {\n // https://github.com/electron-userland/electron-builder/issues/1129\n // Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors\n const errorCode = (e as NodeJS.ErrnoException).code\n this._logger.info(\n `Cannot run installer: error code: ${errorCode}, error message: \"${e.message}\", will be executed again using elevate if EACCES, and will try to use electron.shell.openItem if ENOENT`\n )\n if (errorCode === \"UNKNOWN\" || errorCode === \"EACCES\") {\n callUsingElevation()\n } else if (errorCode === \"ENOENT\") {\n require(\"electron\")\n .shell.openPath(installerPath)\n .catch((err: Error) => this.dispatchError(err))\n } else {\n this.dispatchError(e)\n }\n })\n return true\n }\n\n private async differentialDownloadWebPackage(\n downloadUpdateOptions: DownloadUpdateOptions,\n packageInfo: PackageFileInfo,\n packagePath: string,\n provider: Provider<any>\n ): Promise<boolean> {\n if (packageInfo.blockMapSize == null) {\n return true\n }\n\n try {\n const downloadOptions: DifferentialDownloaderOptions = {\n newUrl: new URL(packageInfo.path),\n oldFile: path.join(this.downloadedUpdateHelper!.cacheDir, CURRENT_APP_PACKAGE_FILE_NAME),\n logger: this._logger,\n newFile: packagePath,\n requestHeaders: this.requestHeaders,\n isUseMultipleRangeRequest: provider.isUseMultipleRangeRequest,\n cancellationToken: downloadUpdateOptions.cancellationToken,\n }\n\n if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {\n downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it)\n }\n\n await new FileWithEmbeddedBlockMapDifferentialDownloader(packageInfo, this.httpExecutor, downloadOptions).download()\n } catch (e: any) {\n this._logger.error(`Cannot download differentially, fallback to full download: ${e.stack || e}`)\n // during test (developer machine mac or linux) we must throw error\n return process.platform === \"win32\"\n }\n return false\n }\n}\n"]}
|
package/out/PacmanUpdater.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { AllPublishOptions } from "builder-util-runtime";
|
|
2
2
|
import { AppAdapter } from "./AppAdapter";
|
|
3
|
-
import { DownloadUpdateOptions } from "./AppUpdater";
|
|
3
|
+
import { DownloadExecutorResult, DownloadUpdateOptions } from "./AppUpdater";
|
|
4
4
|
import { InstallOptions } from "./BaseUpdater";
|
|
5
5
|
import { Logger } from "./types";
|
|
6
6
|
import { LinuxUpdater } from "./LinuxUpdater";
|
|
7
7
|
export declare class PacmanUpdater extends LinuxUpdater {
|
|
8
8
|
constructor(options?: AllPublishOptions | null, app?: AppAdapter);
|
|
9
9
|
/*** @private */
|
|
10
|
-
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<
|
|
10
|
+
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<DownloadExecutorResult>;
|
|
11
11
|
protected doInstall(options: InstallOptions): boolean;
|
|
12
12
|
static installWithCommandRunner(installerPath: string, commandRunner: (commandWithArgs: string[]) => void, logger: Logger): void;
|
|
13
13
|
}
|
package/out/PacmanUpdater.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PacmanUpdater.js","sourceRoot":"","sources":["../src/PacmanUpdater.ts"],"names":[],"mappings":";;;AAIA,mCAAmD;AACnD,mDAA+C;AAC/C,iDAA6C;AAE7C,MAAa,aAAc,SAAQ,2BAAY;IAC7C,YAAY,OAAkC,EAAE,GAAgB;QAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACrB,CAAC;IAED,gBAAgB;IACN,gBAAgB,CAAC,qBAA4C;QACrE,MAAM,QAAQ,GAAG,qBAAqB,CAAC,qBAAqB,CAAC,QAAQ,CAAA;QACrE,MAAM,QAAQ,GAAG,IAAA,mBAAQ,EAAC,QAAQ,CAAC,YAAY,CAAC,qBAAqB,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAE,CAAA;QACzI,OAAO,IAAI,CAAC,eAAe,CAAC;YAC1B,aAAa,EAAE,QAAQ;YACvB,QAAQ;YACR,qBAAqB;YACrB,IAAI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AC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,MAAA,KAAK,CAAC,OAAO,mCAAI,KAAK,CAAC,CAAA;YACnC,MAAM,CAAC,IAAI,CAAC,6EAA6E,CAAC,CAAA;YAE1F,IAAI,CAAC;gBACH,0DAA0D;gBAC1D,aAAa,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAA;gBAC/C,qBAAqB;gBACrB,aAAa,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAA;YAC/D,CAAC;YAAC,OAAO,UAAe,EAAE,CAAC;gBACzB,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAA;gBAC7C,MAAM,UAAU,CAAA;YAClB,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA1DD,sCA0DC","sourcesContent":["import { AllPublishOptions } from \"builder-util-runtime\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { DownloadUpdateOptions } from \"./AppUpdater\"\nimport { InstallOptions } from \"./BaseUpdater\"\nimport { DOWNLOAD_PROGRESS, Logger } from \"./types\"\nimport { findFile } from \"./providers/Provider\"\nimport { LinuxUpdater } from \"./LinuxUpdater\"\n\nexport class PacmanUpdater extends LinuxUpdater {\n constructor(options?: AllPublishOptions | null, app?: AppAdapter) {\n super(options, app)\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<
|
|
1
|
+
{"version":3,"file":"PacmanUpdater.js","sourceRoot":"","sources":["../src/PacmanUpdater.ts"],"names":[],"mappings":";;;AAIA,mCAAmD;AACnD,mDAA+C;AAC/C,iDAA6C;AAE7C,MAAa,aAAc,SAAQ,2BAAY;IAC7C,YAAY,OAAkC,EAAE,GAAgB;QAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACrB,CAAC;IAED,gBAAgB;IACN,gBAAgB,CAAC,qBAA4C;QACrE,MAA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,CAAC;QACD,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;YAC5B,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA,CAAC,uEAAuE;QAC7F,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,CAAC,wBAAwB,CAAC,aAAqB,EAAE,aAAkD,EAAE,MAAc;;QACvH,IAAI,CAAC;YACH,aAAa,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAA;QAC/D,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,MAAA,KAAK,CAAC,OAAO,mCAAI,KAAK,CAAC,CAAA;YACnC,MAAM,CAAC,IAAI,CAAC,6EAA6E,CAAC,CAAA;YAE1F,IAAI,CAAC;gBACH,0DAA0D;gBAC1D,aAAa,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAA;gBAC/C,qBAAqB;gBACrB,aAAa,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAA;YAC/D,CAAC;YAAC,OAAO,UAAe,EAAE,CAAC;gBACzB,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAA;gBAC7C,MAAM,UAAU,CAAA;YAClB,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA1DD,sCA0DC","sourcesContent":["import { AllPublishOptions } from \"builder-util-runtime\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { DownloadExecutorResult, DownloadUpdateOptions } from \"./AppUpdater\"\nimport { InstallOptions } from \"./BaseUpdater\"\nimport { DOWNLOAD_PROGRESS, Logger } from \"./types\"\nimport { findFile } from \"./providers/Provider\"\nimport { LinuxUpdater } from \"./LinuxUpdater\"\n\nexport class PacmanUpdater extends LinuxUpdater {\n constructor(options?: AllPublishOptions | null, app?: AppAdapter) {\n super(options, app)\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<DownloadExecutorResult> {\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), \"pacman\", [\"AppImage\", \"deb\", \"rpm\"])!\n return this.executeDownload({\n fileExtension: \"pacman\",\n fileInfo,\n downloadUpdateOptions,\n task: async (updateFile, downloadOptions) => {\n if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {\n downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it)\n }\n await this.httpExecutor.download(fileInfo.url, updateFile, downloadOptions)\n },\n })\n }\n\n protected doInstall(options: InstallOptions): boolean {\n const installerPath = this.installerPath\n if (installerPath == null) {\n this.dispatchError(new Error(\"No update filepath provided, can't quit and install\"))\n return false\n }\n try {\n PacmanUpdater.installWithCommandRunner(installerPath, this.runCommandWithSudoIfNeeded.bind(this), this._logger)\n } catch (error: any) {\n this.dispatchError(error)\n return false\n }\n if (options.isForceRunAfter) {\n this.app.relaunch() // note: `app` is undefined in tests since vite doesn't run in electron\n }\n return true\n }\n\n static installWithCommandRunner(installerPath: string, commandRunner: (commandWithArgs: string[]) => void, logger: Logger) {\n try {\n commandRunner([\"pacman\", \"-U\", \"--noconfirm\", installerPath])\n } catch (error: any) {\n logger.warn(error.message ?? error)\n logger.warn(\"pacman installation failed, attempting to update package database and retry\")\n\n try {\n // Update package database (not a full upgrade, just sync)\n commandRunner([\"pacman\", \"-Sy\", \"--noconfirm\"])\n // Retry installation\n commandRunner([\"pacman\", \"-U\", \"--noconfirm\", installerPath])\n } catch (retryError: any) {\n logger.error(\"Retry after pacman -Sy failed\")\n throw retryError\n }\n }\n }\n}\n"]}
|
package/out/RpmUpdater.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { AllPublishOptions } from "builder-util-runtime";
|
|
2
2
|
import { AppAdapter } from "./AppAdapter";
|
|
3
|
-
import { DownloadUpdateOptions } from "./AppUpdater";
|
|
3
|
+
import { DownloadExecutorResult, DownloadUpdateOptions } from "./AppUpdater";
|
|
4
4
|
import { InstallOptions } from "./BaseUpdater";
|
|
5
5
|
import { Logger } from "./types";
|
|
6
6
|
import { LinuxUpdater } from "./LinuxUpdater";
|
|
7
7
|
export declare class RpmUpdater extends LinuxUpdater {
|
|
8
8
|
constructor(options?: AllPublishOptions | null, app?: AppAdapter);
|
|
9
9
|
/*** @private */
|
|
10
|
-
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<
|
|
10
|
+
protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<DownloadExecutorResult>;
|
|
11
11
|
protected doInstall(options: InstallOptions): boolean;
|
|
12
12
|
static installWithCommandRunner(packageManager: "zypper" | "dnf" | "yum" | "rpm", installerPath: string, commandRunner: (commandWithArgs: string[]) => void, logger: Logger): void;
|
|
13
13
|
}
|
package/out/RpmUpdater.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpmUpdater.js","sourceRoot":"","sources":["../src/RpmUpdater.ts"],"names":[],"mappings":";;;AAIA,mCAAmD;AACnD,mDAA+C;AAC/C,iDAA6C;AAE7C,MAAa,UAAW,SAAQ,2BAAY;IAC1C,YAAY,OAAkC,EAAE,GAAgB;QAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACrB,CAAC;IAED,gBAAgB;IACN,gBAAgB,CAAC,qBAA4C;QACrE,MAAM,QAAQ,GAAG,qBAAqB,CAAC,qBAAqB,CAAC,QAAQ,CAAA;QACrE,MAAM,QAAQ,GAAG,IAAA,mBAAQ,EAAC,QAAQ,CAAC,YAAY,CAAC,qBAAqB,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAE,CAAA;QACzI,OAAO,IAAI,CAAC,eAAe,CAAC;YAC1B,aAAa,EAAE,K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;IACb,CAAC;IAED,MAAM,CAAC,wBAAwB,CAAC,cAAgD,EAAE,aAAqB,EAAE,aAAkD,EAAE,MAAc;QACzK,IAAI,cAAc,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,aAAa,CAAC,CAAC,QAAQ,EAAE,mBAAmB,EAAE,cAAc,EAAE,SAAS,EAAE,sBAAsB,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAA;QAC/H,CAAC;QACD,IAAI,cAAc,KAAK,KAAK,EAAE,CAAC;YAC7B,OAAO,aAAa,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAA;QAC/E,CAAC;QACD,IAAI,cAAc,KAAK,KAAK,EAAE,CAAC;YAC7B,OAAO,aAAa,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAA;QAC/E,CAAC;QACD,IAAI,cAAc,KAAK,KAAK,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAA;YACnE,OAAO,aAAa,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAA;QACrG,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,mBAAmB,cAAc,gBAAgB,CAAC,CAAA;IACpE,CAAC;CACF;AA3DD,gCA2DC","sourcesContent":["import { AllPublishOptions } from \"builder-util-runtime\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { DownloadUpdateOptions } from \"./AppUpdater\"\nimport { InstallOptions } from \"./BaseUpdater\"\nimport { DOWNLOAD_PROGRESS, Logger } from \"./types\"\nimport { findFile } from \"./providers/Provider\"\nimport { LinuxUpdater } from \"./LinuxUpdater\"\n\nexport class RpmUpdater extends LinuxUpdater {\n constructor(options?: AllPublishOptions | null, app?: AppAdapter) {\n super(options, app)\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<
|
|
1
|
+
{"version":3,"file":"RpmUpdater.js","sourceRoot":"","sources":["../src/RpmUpdater.ts"],"names":[],"mappings":";;;AAIA,mCAAmD;AACnD,mDAA+C;AAC/C,iDAA6C;AAE7C,MAAa,UAAW,SAAQ,2BAAY;IAC1C,YAAY,OAAkC,EAAE,GAAgB;QAC9D,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACrB,CAAC;IAED,gBAAgB;IACN,gBAAgB,CAAC,qBAA4C;QACrE,MAAM,QAAQ,GAAG,qBAAqB,CAAC,qBAAqB,CAAC,QAAQ,CAAA;QACrE,MAAM,QAAQ,GAAG,IAAA,mBAAQ,EAAC,QAAQ,CAAC,YAAY,CAAC,qBAAqB,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAE,CAAA;QACzI,OAAO,IAAI,CAAC,eAAe,CAAC;YAC1B,aAAa,EAAE,KAAK;YACpB,QAAQ;YACR,qBAAqB;YACrB,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,EAAE;gBAC1C,IAAI,IAAI,CAAC,aAAa,CAAC,yBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC9C,eAAe,CAAC,UAAU,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAiB,EAAE,EAAE,CAAC,CAAA;gBACrE,CAAC;gBACD,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,eAAe,CAAC,CAAA;YAC7E,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;IAES,SAAS,CAAC,OAAuB;QACzC,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAA;QACxC,IAAI,aAAa,IAAI,IAAI,EAAE,CAAC;YAC1B,IAAI,CA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C,CAAA;QAC/E,CAAC;QACD,IAAI,cAAc,KAAK,KAAK,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAA;YACnE,OAAO,aAAa,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAA;QACrG,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,mBAAmB,cAAc,gBAAgB,CAAC,CAAA;IACpE,CAAC;CACF;AA3DD,gCA2DC","sourcesContent":["import { AllPublishOptions } from \"builder-util-runtime\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { DownloadExecutorResult, DownloadUpdateOptions } from \"./AppUpdater\"\nimport { InstallOptions } from \"./BaseUpdater\"\nimport { DOWNLOAD_PROGRESS, Logger } from \"./types\"\nimport { findFile } from \"./providers/Provider\"\nimport { LinuxUpdater } from \"./LinuxUpdater\"\n\nexport class RpmUpdater extends LinuxUpdater {\n constructor(options?: AllPublishOptions | null, app?: AppAdapter) {\n super(options, app)\n }\n\n /*** @private */\n protected doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<DownloadExecutorResult> {\n const provider = downloadUpdateOptions.updateInfoAndProvider.provider\n const fileInfo = findFile(provider.resolveFiles(downloadUpdateOptions.updateInfoAndProvider.info), \"rpm\", [\"AppImage\", \"deb\", \"pacman\"])!\n return this.executeDownload({\n fileExtension: \"rpm\",\n fileInfo,\n downloadUpdateOptions,\n task: async (updateFile, downloadOptions) => {\n if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) {\n downloadOptions.onProgress = it => this.emit(DOWNLOAD_PROGRESS, it)\n }\n await this.httpExecutor.download(fileInfo.url, updateFile, downloadOptions)\n },\n })\n }\n\n protected doInstall(options: InstallOptions): boolean {\n const installerPath = this.installerPath\n if (installerPath == null) {\n this.dispatchError(new Error(\"No update filepath provided, can't quit and install\"))\n return false\n }\n\n const priorityList = [\"zypper\", \"dnf\", \"yum\", \"rpm\"]\n const packageManager = this.detectPackageManager(priorityList)\n try {\n RpmUpdater.installWithCommandRunner(packageManager as any, installerPath, this.runCommandWithSudoIfNeeded.bind(this), this._logger)\n } catch (error: any) {\n this.dispatchError(error)\n return false\n }\n if (options.isForceRunAfter) {\n this.app.relaunch()\n }\n return true\n }\n\n static installWithCommandRunner(packageManager: \"zypper\" | \"dnf\" | \"yum\" | \"rpm\", installerPath: string, commandRunner: (commandWithArgs: string[]) => void, logger: Logger) {\n if (packageManager === \"zypper\") {\n return commandRunner([\"zypper\", \"--non-interactive\", \"--no-refresh\", \"install\", \"--allow-unsigned-rpm\", \"-f\", installerPath])\n }\n if (packageManager === \"dnf\") {\n return commandRunner([\"dnf\", \"install\", \"--nogpgcheck\", \"-y\", installerPath])\n }\n if (packageManager === \"yum\") {\n return commandRunner([\"yum\", \"install\", \"--nogpgcheck\", \"-y\", installerPath])\n }\n if (packageManager === \"rpm\") {\n logger.warn(\"Installing with rpm only (no dependency resolution).\")\n return commandRunner([\"rpm\", \"-Uvh\", \"--replacepkgs\", \"--replacefiles\", \"--nodeps\", installerPath])\n }\n throw new Error(`Package manager ${packageManager} not supported`)\n }\n}\n"]}
|
|
@@ -21,11 +21,12 @@ export declare class DataSplitter extends Writable {
|
|
|
21
21
|
private transferred;
|
|
22
22
|
private delta;
|
|
23
23
|
partIndex: number;
|
|
24
|
-
private
|
|
24
|
+
private headerListTail;
|
|
25
25
|
private readState;
|
|
26
26
|
private ignoreByteCount;
|
|
27
27
|
private remainingPartDataCount;
|
|
28
|
-
private readonly
|
|
28
|
+
private readonly boundaryTextLength;
|
|
29
|
+
private boundaryLength;
|
|
29
30
|
constructor(out: Writable, options: PartListDataTask, partIndexToTaskIndex: Map<number, number>, boundary: string, partIndexToLength: Array<number>, finishHandler: () => any, grandTotalBytes: number, onProgress?: ((info: ProgressInfo) => any) | undefined);
|
|
30
31
|
get isFinished(): boolean;
|
|
31
32
|
_write(data: Buffer, encoding: string, callback: (error?: Error) => void): void;
|
|
@@ -6,7 +6,26 @@ const builder_util_runtime_1 = require("builder-util-runtime");
|
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const stream_1 = require("stream");
|
|
8
8
|
const downloadPlanBuilder_1 = require("./downloadPlanBuilder");
|
|
9
|
-
const
|
|
9
|
+
const CRLF_HEADER_LIST_END = Buffer.from("\r\n\r\n");
|
|
10
|
+
// RFC 2046 requires CRLF, but some CDNs (e.g. Qiniu's "web cache") emit bare LF in multipart/byteranges responses.
|
|
11
|
+
const LF_HEADER_LIST_END = Buffer.from("\n\n");
|
|
12
|
+
// A terminator may be split across two chunks: keep this many trailing bytes of an unfinished header list.
|
|
13
|
+
const HEADER_LIST_END_CARRY = CRLF_HEADER_LIST_END.length - 1;
|
|
14
|
+
// Parts are separated by "<EOL>--boundary"; these are the sizes of the "<EOL>--" prefix.
|
|
15
|
+
const CRLF_DELIMITER_PREFIX_LENGTH = "\r\n--".length;
|
|
16
|
+
const LF_DELIMITER_PREFIX_LENGTH = "\n--".length;
|
|
17
|
+
function findHeaderListEnd(data) {
|
|
18
|
+
const crlf = data.indexOf(CRLF_HEADER_LIST_END);
|
|
19
|
+
// "\r\n\r\n" never contains "\n\n", so whichever terminator comes first tells the line ending in use
|
|
20
|
+
const lf = data.indexOf(LF_HEADER_LIST_END);
|
|
21
|
+
if (lf !== -1 && (crlf === -1 || lf < crlf)) {
|
|
22
|
+
return { end: lf + LF_HEADER_LIST_END.length, lineFeedOnly: true };
|
|
23
|
+
}
|
|
24
|
+
if (crlf !== -1) {
|
|
25
|
+
return { end: crlf + CRLF_HEADER_LIST_END.length, lineFeedOnly: false };
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
10
29
|
var ReadState;
|
|
11
30
|
(function (ReadState) {
|
|
12
31
|
ReadState[ReadState["INIT"] = 0] = "INIT";
|
|
@@ -43,11 +62,14 @@ class DataSplitter extends stream_1.Writable {
|
|
|
43
62
|
this.transferred = 0; // total number of bytes transferred
|
|
44
63
|
this.delta = 0; // number of bytes transferred since last update, reset after each update
|
|
45
64
|
this.partIndex = -1;
|
|
46
|
-
|
|
65
|
+
// Trailing bytes (at most HEADER_LIST_END_CARRY) of a header list that is not complete yet. Header lists are ignored,
|
|
66
|
+
// so nothing more needs to be kept — only enough to find a terminator that straddles two chunks.
|
|
67
|
+
this.headerListTail = null;
|
|
47
68
|
this.readState = ReadState.INIT;
|
|
48
69
|
this.ignoreByteCount = 0;
|
|
49
70
|
this.remainingPartDataCount = 0;
|
|
50
71
|
this.actualPartLength = 0;
|
|
72
|
+
this.boundaryTextLength = boundary.length;
|
|
51
73
|
this.boundaryLength = boundary.length + 4; /* size of \r\n-- */
|
|
52
74
|
// first chunk doesn't start with \r\n
|
|
53
75
|
this.ignoreByteCount = this.boundaryLength - 2;
|
|
@@ -107,8 +129,6 @@ class DataSplitter extends stream_1.Writable {
|
|
|
107
129
|
}
|
|
108
130
|
start = headerListEnd;
|
|
109
131
|
this.readState = ReadState.BODY;
|
|
110
|
-
// header list is ignored, we don't need it
|
|
111
|
-
this.headerListBuffer = null;
|
|
112
132
|
}
|
|
113
133
|
while (true) {
|
|
114
134
|
if (this.readState === ReadState.BODY) {
|
|
@@ -179,18 +199,19 @@ class DataSplitter extends stream_1.Writable {
|
|
|
179
199
|
});
|
|
180
200
|
}
|
|
181
201
|
searchHeaderListEnd(chunk, readOffset) {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
this.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
this.headerListBuffer = Buffer.concat([this.headerListBuffer, partialChunk]);
|
|
202
|
+
const tail = this.headerListTail;
|
|
203
|
+
const carried = tail == null ? 0 : tail.length;
|
|
204
|
+
const data = tail == null ? chunk.subarray(readOffset) : Buffer.concat([tail, chunk.subarray(readOffset)]);
|
|
205
|
+
const found = findHeaderListEnd(data);
|
|
206
|
+
if (found != null) {
|
|
207
|
+
this.headerListTail = null;
|
|
208
|
+
// the separator size follows the line ending the server actually uses
|
|
209
|
+
this.boundaryLength = this.boundaryTextLength + (found.lineFeedOnly ? LF_DELIMITER_PREFIX_LENGTH : CRLF_DELIMITER_PREFIX_LENGTH);
|
|
210
|
+
// the carried bytes were already searched, so the terminator always ends inside the current chunk
|
|
211
|
+
return readOffset + found.end - carried;
|
|
193
212
|
}
|
|
213
|
+
// not all headers data were received; copy the tail so the chunk itself is not retained
|
|
214
|
+
this.headerListTail = Buffer.from(data.subarray(Math.max(0, data.length - HEADER_LIST_END_CARRY)));
|
|
194
215
|
return -1;
|
|
195
216
|
}
|
|
196
217
|
onPartEnd() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataSplitter.js","sourceRoot":"","sources":["../../src/differentialDownloader/DataSplitter.ts"],"names":[],"mappings":";;;AAqBA,4BAaC;AAlCD,+DAA+C;AAC/C,2BAAqC;AACrC,mCAAiC;AACjC,+DAAgE;AAGhE,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AAE3C,IAAK,SAIJ;AAJD,WAAK,SAAS;IACZ,yCAAI,CAAA;IACJ,6CAAM,CAAA;IACN,yCAAI,CAAA;AACN,CAAC,EAJI,SAAS,KAAT,SAAS,QAIb;AASD,SAAgB,QAAQ,CAAC,IAAe,EAAE,GAAa,EAAE,SAAiB,EAAE,MAA8B,EAAE,OAAmB;IAC7H,MAAM,UAAU,GAAG,IAAA,qBAAgB,EAAC,EAAE,EAAE;QACtC,EAAE,EAAE,SAAS;QACb,SAAS,EAAE,KAAK;QAChB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,mBAAmB;QACnB,GAAG,EAAE,IAAI,CAAC,GAAG,GAAG,CAAC;KAClB,CAAC,CAAA;IACF,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAC9B,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO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CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF;AAnOD,oCAmOC","sourcesContent":["import { newError } from \"builder-util-runtime\"\nimport { createReadStream } from \"fs\"\nimport { Writable } from \"stream\"\nimport { Operation, OperationKind } from \"./downloadPlanBuilder\"\nimport { ProgressInfo } from \"./ProgressDifferentialDownloadCallbackTransform\"\n\nconst DOUBLE_CRLF = Buffer.from(\"\\r\\n\\r\\n\")\n\nenum ReadState {\n INIT,\n HEADER,\n BODY,\n}\n\nexport interface PartListDataTask {\n readonly oldFileFd: number\n readonly tasks: Array<Operation>\n readonly start: number\n readonly end: number\n}\n\nexport function copyData(task: Operation, out: Writable, oldFileFd: number, reject: (error: Error) => void, resolve: () => void): void {\n const readStream = createReadStream(\"\", {\n fd: oldFileFd,\n autoClose: false,\n start: task.start,\n // end is inclusive\n end: task.end - 1,\n })\n readStream.on(\"error\", reject)\n readStream.once(\"end\", resolve)\n readStream.pipe(out, {\n end: false,\n })\n}\n\nexport class DataSplitter extends Writable {\n // properties for progress update calculations\n private start = Date.now() // download start time used to calculate average rate\n private nextUpdate = this.start + 1000 // timestamp of next update to prevent updates more often than once per second\n private transferred = 0 // total number of bytes transferred\n private delta = 0 // number of bytes transferred since last update, reset after each update\n\n partIndex = -1\n\n private headerListBuffer: Buffer | null = null\n private readState = ReadState.INIT\n private ignoreByteCount = 0\n private remainingPartDataCount = 0\n\n private readonly boundaryLength: number\n\n constructor(\n private readonly out: Writable,\n private readonly options: PartListDataTask,\n private readonly partIndexToTaskIndex: Map<number, number>,\n boundary: string,\n private readonly partIndexToLength: Array<number>,\n private readonly finishHandler: () => any,\n private readonly grandTotalBytes: number,\n private readonly onProgress?: (info: ProgressInfo) => any\n ) {\n super()\n\n this.boundaryLength = boundary.length + 4 /* size of \\r\\n-- */\n // first chunk doesn't start with \\r\\n\n this.ignoreByteCount = this.boundaryLength - 2\n }\n\n get isFinished(): boolean {\n return this.partIndex === this.partIndexToLength.length\n }\n\n // noinspection JSUnusedGlobalSymbols\n _write(data: Buffer, encoding: string, callback: (error?: Error) => void): void {\n if (this.isFinished) {\n console.error(`Trailing ignored data: ${data.length} bytes`)\n return\n }\n\n this.handleData(data)\n .then(() => {\n if (this.onProgress) {\n const now = Date.now()\n if ((now >= this.nextUpdate || this.transferred === this.grandTotalBytes) && this.grandTotalBytes && (now - this.start) / 1000) {\n this.nextUpdate = now + 1000\n\n this.onProgress({\n total: this.grandTotalBytes,\n delta: this.delta,\n transferred: this.transferred,\n percent: (this.transferred / this.grandTotalBytes) * 100,\n bytesPerSecond: Math.round(this.transferred / ((now - this.start) / 1000)),\n })\n this.delta = 0\n }\n }\n\n callback()\n })\n .catch(callback)\n }\n\n private async handleData(chunk: Buffer): Promise<undefined> {\n let start = 0\n\n if (this.ignoreByteCount !== 0 && this.remainingPartDataCount !== 0) {\n throw newError(\"Internal error\", \"ERR_DATA_SPLITTER_BYTE_COUNT_MISMATCH\")\n }\n\n if (this.ignoreByteCount > 0) {\n const toIgnore = Math.min(this.ignoreByteCount, chunk.length)\n this.ignoreByteCount -= toIgnore\n start = toIgnore\n } else if (this.remainingPartDataCount > 0) {\n const toRead = Math.min(this.remainingPartDataCount, chunk.length)\n this.remainingPartDataCount -= toRead\n await this.processPartData(chunk, 0, toRead)\n start = toRead\n }\n\n if (start === chunk.length) {\n return\n }\n\n if (this.readState === ReadState.HEADER) {\n const headerListEnd = this.searchHeaderListEnd(chunk, start)\n if (headerListEnd === -1) {\n return\n }\n\n start = headerListEnd\n this.readState = ReadState.BODY\n // header list is ignored, we don't need it\n this.headerListBuffer = null\n }\n\n while (true) {\n if (this.readState === ReadState.BODY) {\n this.readState = ReadState.INIT\n } else {\n this.partIndex++\n\n let taskIndex = this.partIndexToTaskIndex.get(this.partIndex)\n if (taskIndex == null) {\n if (this.isFinished) {\n taskIndex = this.options.end\n } else {\n throw newError(\"taskIndex is null\", \"ERR_DATA_SPLITTER_TASK_INDEX_IS_NULL\")\n }\n }\n\n const prevTaskIndex = this.partIndex === 0 ? this.options.start : this.partIndexToTaskIndex.get(this.partIndex - 1)! + 1 /* prev part is download, next maybe copy */\n if (prevTaskIndex < taskIndex) {\n await this.copyExistingData(prevTaskIndex, taskIndex)\n } else if (prevTaskIndex > taskIndex) {\n throw newError(\"prevTaskIndex must be < taskIndex\", \"ERR_DATA_SPLITTER_TASK_INDEX_ASSERT_FAILED\")\n }\n\n if (this.isFinished) {\n this.onPartEnd()\n this.finishHandler()\n return\n }\n\n start = this.searchHeaderListEnd(chunk, start)\n\n if (start === -1) {\n this.readState = ReadState.HEADER\n return\n }\n }\n\n const partLength = this.partIndexToLength[this.partIndex]\n const end = start + partLength\n const effectiveEnd = Math.min(end, chunk.length)\n await this.processPartStarted(chunk, start, effectiveEnd)\n this.remainingPartDataCount = partLength - (effectiveEnd - start)\n if (this.remainingPartDataCount > 0) {\n return\n }\n\n start = end + this.boundaryLength\n if (start >= chunk.length) {\n this.ignoreByteCount = this.boundaryLength - (chunk.length - end)\n return\n }\n }\n }\n\n private copyExistingData(index: number, end: number): Promise<void> {\n return new Promise((resolve, reject) => {\n const w = (): void => {\n if (index === end) {\n resolve()\n return\n }\n\n const task = this.options.tasks[index]\n if (task.kind !== OperationKind.COPY) {\n reject(new Error(\"Task kind must be COPY\"))\n return\n }\n\n copyData(task, this.out, this.options.oldFileFd, reject, () => {\n index++\n w()\n })\n }\n w()\n })\n }\n\n private searchHeaderListEnd(chunk: Buffer, readOffset: number): number {\n const headerListEnd = chunk.indexOf(DOUBLE_CRLF, readOffset)\n if (headerListEnd !== -1) {\n return headerListEnd + DOUBLE_CRLF.length\n }\n\n // not all headers data were received, save to buffer\n const partialChunk = readOffset === 0 ? chunk : chunk.slice(readOffset)\n if (this.headerListBuffer == null) {\n this.headerListBuffer = partialChunk\n } else {\n this.headerListBuffer = Buffer.concat([this.headerListBuffer, partialChunk])\n }\n return -1\n }\n\n private actualPartLength = 0\n\n private onPartEnd(): void {\n const expectedLength = this.partIndexToLength[this.partIndex - 1]\n if (this.actualPartLength !== expectedLength) {\n throw newError(`Expected length: ${expectedLength} differs from actual: ${this.actualPartLength}`, \"ERR_DATA_SPLITTER_LENGTH_MISMATCH\")\n }\n this.actualPartLength = 0\n }\n\n private processPartStarted(data: Buffer, start: number, end: number): Promise<void> {\n if (this.partIndex !== 0) {\n this.onPartEnd()\n }\n return this.processPartData(data, start, end)\n }\n\n private processPartData(data: Buffer, start: number, end: number): Promise<void> {\n this.actualPartLength += end - start\n this.transferred += end - start\n this.delta += end - start\n const out = this.out\n if (out.write(start === 0 && data.length === end ? data : data.slice(start, end))) {\n return Promise.resolve()\n } else {\n return new Promise((resolve, reject) => {\n out.on(\"error\", reject)\n out.once(\"drain\", () => {\n out.removeListener(\"error\", reject)\n resolve()\n })\n })\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DataSplitter.js","sourceRoot":"","sources":["../../src/differentialDownloader/DataSplitter.ts"],"names":[],"mappings":";;;AA+CA,4BAaC;AA5DD,+DAA+C;AAC/C,2BAAqC;AACrC,mCAAiC;AACjC,+DAAgE;AAGhE,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AACpD,mHAAmH;AACnH,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AAC9C,2GAA2G;AAC3G,MAAM,qBAAqB,GAAG,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAA;AAC7D,yFAAyF;AACzF,MAAM,4BAA4B,GAAG,QAAQ,CAAC,MAAM,CAAA;AACpD,MAAM,0BAA0B,GAAG,MAAM,CAAC,MAAM,CAAA;AAQhD,SAAS,iBAAiB,CAAC,IAAY;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAA;IAC/C,qGAAqG;IACrG,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAC3C,IAAI,EAAE,KAAK,CAAC,CAAC,IAA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AO,EAAE,MAAM,CAAC,CAAA;oBACnC,OAAO,EAAE,CAAA;gBACX,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF;AAxOD,oCAwOC","sourcesContent":["import { newError } from \"builder-util-runtime\"\nimport { createReadStream } from \"fs\"\nimport { Writable } from \"stream\"\nimport { Operation, OperationKind } from \"./downloadPlanBuilder\"\nimport { ProgressInfo } from \"./ProgressDifferentialDownloadCallbackTransform\"\n\nconst CRLF_HEADER_LIST_END = Buffer.from(\"\\r\\n\\r\\n\")\n// RFC 2046 requires CRLF, but some CDNs (e.g. Qiniu's \"web cache\") emit bare LF in multipart/byteranges responses.\nconst LF_HEADER_LIST_END = Buffer.from(\"\\n\\n\")\n// A terminator may be split across two chunks: keep this many trailing bytes of an unfinished header list.\nconst HEADER_LIST_END_CARRY = CRLF_HEADER_LIST_END.length - 1\n// Parts are separated by \"<EOL>--boundary\"; these are the sizes of the \"<EOL>--\" prefix.\nconst CRLF_DELIMITER_PREFIX_LENGTH = \"\\r\\n--\".length\nconst LF_DELIMITER_PREFIX_LENGTH = \"\\n--\".length\n\ninterface HeaderListEnd {\n // offset just past the terminator\n readonly end: number\n readonly lineFeedOnly: boolean\n}\n\nfunction findHeaderListEnd(data: Buffer): HeaderListEnd | null {\n const crlf = data.indexOf(CRLF_HEADER_LIST_END)\n // \"\\r\\n\\r\\n\" never contains \"\\n\\n\", so whichever terminator comes first tells the line ending in use\n const lf = data.indexOf(LF_HEADER_LIST_END)\n if (lf !== -1 && (crlf === -1 || lf < crlf)) {\n return { end: lf + LF_HEADER_LIST_END.length, lineFeedOnly: true }\n }\n if (crlf !== -1) {\n return { end: crlf + CRLF_HEADER_LIST_END.length, lineFeedOnly: false }\n }\n return null\n}\n\nenum ReadState {\n INIT,\n HEADER,\n BODY,\n}\n\nexport interface PartListDataTask {\n readonly oldFileFd: number\n readonly tasks: Array<Operation>\n readonly start: number\n readonly end: number\n}\n\nexport function copyData(task: Operation, out: Writable, oldFileFd: number, reject: (error: Error) => void, resolve: () => void): void {\n const readStream = createReadStream(\"\", {\n fd: oldFileFd,\n autoClose: false,\n start: task.start,\n // end is inclusive\n end: task.end - 1,\n })\n readStream.on(\"error\", reject)\n readStream.once(\"end\", resolve)\n readStream.pipe(out, {\n end: false,\n })\n}\n\nexport class DataSplitter extends Writable {\n // properties for progress update calculations\n private start = Date.now() // download start time used to calculate average rate\n private nextUpdate = this.start + 1000 // timestamp of next update to prevent updates more often than once per second\n private transferred = 0 // total number of bytes transferred\n private delta = 0 // number of bytes transferred since last update, reset after each update\n\n partIndex = -1\n\n // Trailing bytes (at most HEADER_LIST_END_CARRY) of a header list that is not complete yet. Header lists are ignored,\n // so nothing more needs to be kept — only enough to find a terminator that straddles two chunks.\n private headerListTail: Buffer | null = null\n private readState = ReadState.INIT\n private ignoreByteCount = 0\n private remainingPartDataCount = 0\n\n private readonly boundaryTextLength: number\n // size of \"<EOL>--boundary\" between parts; corrected once the line ending used by the server is known\n private boundaryLength: number\n\n constructor(\n private readonly out: Writable,\n private readonly options: PartListDataTask,\n private readonly partIndexToTaskIndex: Map<number, number>,\n boundary: string,\n private readonly partIndexToLength: Array<number>,\n private readonly finishHandler: () => any,\n private readonly grandTotalBytes: number,\n private readonly onProgress?: (info: ProgressInfo) => any\n ) {\n super()\n\n this.boundaryTextLength = boundary.length\n this.boundaryLength = boundary.length + 4 /* size of \\r\\n-- */\n // first chunk doesn't start with \\r\\n\n this.ignoreByteCount = this.boundaryLength - 2\n }\n\n get isFinished(): boolean {\n return this.partIndex === this.partIndexToLength.length\n }\n\n // noinspection JSUnusedGlobalSymbols\n _write(data: Buffer, encoding: string, callback: (error?: Error) => void): void {\n if (this.isFinished) {\n console.error(`Trailing ignored data: ${data.length} bytes`)\n return\n }\n\n this.handleData(data)\n .then(() => {\n if (this.onProgress) {\n const now = Date.now()\n if ((now >= this.nextUpdate || this.transferred === this.grandTotalBytes) && this.grandTotalBytes && (now - this.start) / 1000) {\n this.nextUpdate = now + 1000\n\n this.onProgress({\n total: this.grandTotalBytes,\n delta: this.delta,\n transferred: this.transferred,\n percent: (this.transferred / this.grandTotalBytes) * 100,\n bytesPerSecond: Math.round(this.transferred / ((now - this.start) / 1000)),\n })\n this.delta = 0\n }\n }\n\n callback()\n })\n .catch(callback)\n }\n\n private async handleData(chunk: Buffer): Promise<undefined> {\n let start = 0\n\n if (this.ignoreByteCount !== 0 && this.remainingPartDataCount !== 0) {\n throw newError(\"Internal error\", \"ERR_DATA_SPLITTER_BYTE_COUNT_MISMATCH\")\n }\n\n if (this.ignoreByteCount > 0) {\n const toIgnore = Math.min(this.ignoreByteCount, chunk.length)\n this.ignoreByteCount -= toIgnore\n start = toIgnore\n } else if (this.remainingPartDataCount > 0) {\n const toRead = Math.min(this.remainingPartDataCount, chunk.length)\n this.remainingPartDataCount -= toRead\n await this.processPartData(chunk, 0, toRead)\n start = toRead\n }\n\n if (start === chunk.length) {\n return\n }\n\n if (this.readState === ReadState.HEADER) {\n const headerListEnd = this.searchHeaderListEnd(chunk, start)\n if (headerListEnd === -1) {\n return\n }\n\n start = headerListEnd\n this.readState = ReadState.BODY\n }\n\n while (true) {\n if (this.readState === ReadState.BODY) {\n this.readState = ReadState.INIT\n } else {\n this.partIndex++\n\n let taskIndex = this.partIndexToTaskIndex.get(this.partIndex)\n if (taskIndex == null) {\n if (this.isFinished) {\n taskIndex = this.options.end\n } else {\n throw newError(\"taskIndex is null\", \"ERR_DATA_SPLITTER_TASK_INDEX_IS_NULL\")\n }\n }\n\n const prevTaskIndex = this.partIndex === 0 ? this.options.start : this.partIndexToTaskIndex.get(this.partIndex - 1)! + 1 /* prev part is download, next maybe copy */\n if (prevTaskIndex < taskIndex) {\n await this.copyExistingData(prevTaskIndex, taskIndex)\n } else if (prevTaskIndex > taskIndex) {\n throw newError(\"prevTaskIndex must be < taskIndex\", \"ERR_DATA_SPLITTER_TASK_INDEX_ASSERT_FAILED\")\n }\n\n if (this.isFinished) {\n this.onPartEnd()\n this.finishHandler()\n return\n }\n\n start = this.searchHeaderListEnd(chunk, start)\n\n if (start === -1) {\n this.readState = ReadState.HEADER\n return\n }\n }\n\n const partLength = this.partIndexToLength[this.partIndex]\n const end = start + partLength\n const effectiveEnd = Math.min(end, chunk.length)\n await this.processPartStarted(chunk, start, effectiveEnd)\n this.remainingPartDataCount = partLength - (effectiveEnd - start)\n if (this.remainingPartDataCount > 0) {\n return\n }\n\n start = end + this.boundaryLength\n if (start >= chunk.length) {\n this.ignoreByteCount = this.boundaryLength - (chunk.length - end)\n return\n }\n }\n }\n\n private copyExistingData(index: number, end: number): Promise<void> {\n return new Promise((resolve, reject) => {\n const w = (): void => {\n if (index === end) {\n resolve()\n return\n }\n\n const task = this.options.tasks[index]\n if (task.kind !== OperationKind.COPY) {\n reject(new Error(\"Task kind must be COPY\"))\n return\n }\n\n copyData(task, this.out, this.options.oldFileFd, reject, () => {\n index++\n w()\n })\n }\n w()\n })\n }\n\n private searchHeaderListEnd(chunk: Buffer, readOffset: number): number {\n const tail = this.headerListTail\n const carried = tail == null ? 0 : tail.length\n const data = tail == null ? chunk.subarray(readOffset) : Buffer.concat([tail, chunk.subarray(readOffset)])\n const found = findHeaderListEnd(data)\n if (found != null) {\n this.headerListTail = null\n // the separator size follows the line ending the server actually uses\n this.boundaryLength = this.boundaryTextLength + (found.lineFeedOnly ? LF_DELIMITER_PREFIX_LENGTH : CRLF_DELIMITER_PREFIX_LENGTH)\n // the carried bytes were already searched, so the terminator always ends inside the current chunk\n return readOffset + found.end - carried\n }\n\n // not all headers data were received; copy the tail so the chunk itself is not retained\n this.headerListTail = Buffer.from(data.subarray(Math.max(0, data.length - HEADER_LIST_END_CARRY)))\n return -1\n }\n\n private actualPartLength = 0\n\n private onPartEnd(): void {\n const expectedLength = this.partIndexToLength[this.partIndex - 1]\n if (this.actualPartLength !== expectedLength) {\n throw newError(`Expected length: ${expectedLength} differs from actual: ${this.actualPartLength}`, \"ERR_DATA_SPLITTER_LENGTH_MISMATCH\")\n }\n this.actualPartLength = 0\n }\n\n private processPartStarted(data: Buffer, start: number, end: number): Promise<void> {\n if (this.partIndex !== 0) {\n this.onPartEnd()\n }\n return this.processPartData(data, start, end)\n }\n\n private processPartData(data: Buffer, start: number, end: number): Promise<void> {\n this.actualPartLength += end - start\n this.transferred += end - start\n this.delta += end - start\n const out = this.out\n if (out.write(start === 0 && data.length === end ? data : data.slice(start, end))) {\n return Promise.resolve()\n } else {\n return new Promise((resolve, reject) => {\n out.on(\"error\", reject)\n out.once(\"drain\", () => {\n out.removeListener(\"error\", reject)\n resolve()\n })\n })\n }\n }\n}\n"]}
|
|
@@ -83,11 +83,31 @@ function doExecuteTasks(differentialDownloader, options, out, resolve, reject) {
|
|
|
83
83
|
reject(new Error(`Content-Type "multipart/byteranges" is expected, but got "${contentType}"`));
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
|
|
86
|
+
// The watchdog below only exists for a response that ends before every part was handled. It must not outlive a
|
|
87
|
+
// successful batch: the next batch reuses the same `reject`, so a stale watchdog used to fail any multi-batch
|
|
88
|
+
// download whose later batches took longer than the grace period.
|
|
89
|
+
let isBatchFinished = false;
|
|
90
|
+
let watchdog = null;
|
|
91
|
+
const onBatchFinished = () => {
|
|
92
|
+
isBatchFinished = true;
|
|
93
|
+
if (watchdog != null) {
|
|
94
|
+
clearTimeout(watchdog);
|
|
95
|
+
watchdog = null;
|
|
96
|
+
}
|
|
97
|
+
resolve();
|
|
98
|
+
};
|
|
99
|
+
const dicer = new DataSplitter_1.DataSplitter(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, onBatchFinished, grandTotalBytes, differentialDownloader.options.onProgress);
|
|
87
100
|
dicer.on("error", reject);
|
|
88
101
|
response.pipe(dicer);
|
|
89
102
|
response.on("end", () => {
|
|
90
|
-
|
|
103
|
+
if (isBatchFinished) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
watchdog = setTimeout(() => {
|
|
107
|
+
watchdog = null;
|
|
108
|
+
if (isBatchFinished) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
91
111
|
request.abort();
|
|
92
112
|
reject(new Error("Response ends without calling any handlers"));
|
|
93
113
|
}, 10000);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multipleRangeDownloader.js","sourceRoot":"","sources":["../../src/differentialDownloader/multipleRangeDownloader.ts"],"names":[],"mappings":";;AAOA,wFA+BC;AAoFD,wDAeC;AAzID,+DAAqE;AAGrE,iDAAyE;AAEzE,+DAAgE;AAEhE,SAAgB,sCAAsC,CACpD,sBAA8C,EAC9C,KAAuB,EACvB,GAAa,EACb,SAAiB,EACjB,MAA8B;IAE9B,MAAM,CAAC,GAAG,CAAC,UAAkB,EAAQ,EAAE;QACrC,IAAI,UAAU,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YAC/B,IAAI,sBAAsB,CAAC,kBAAkB,IAAI,IAAI,EAAE,CAAC;gBACtD,GAAG,CAAC,KAAK,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAA;YACtD,CAAC;YACD,GAAG,CAAC,GAAG,EAAE,CAAA;YACT,OAAM;QACR,CAAC;QAED,MAAM,UAAU,GAAG,UAAU,GAAG,IAAI,CAAA;QACpC,cAAc,CACZ,sBAAsB,EACtB;YACE,KAAK;YACL,KAAK,EAAE,UAAU;YACjB,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC;YACvC,SAAS;SACV,EACD,GAAG,EACH,GAAG,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,EACnB,MAAM,CACP,CAAA;IACH,CAAC,CAAA;IACD,OAAO,CAAC,CAAA;AACV,CAAC;AAED,SAAS,cAAc,CAAC,sBAA8C,EAAE,OAAyB,EAAE,GAAa,EAAE,OAAmB,EAAE,MAA8B;IACnK,IAAI,MAAM,GAAG,QAAQ,CAAA;IACrB,IAAI,SAAS,GAAG,CAAC,CAAA;IACjB,IAAI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I,QAAQ,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,IAAA,oCAAa,EAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;QAC7D,IAAI,YAAY,IAAI,IAAI,IAAI,YAAY,KAAK,MAAM,EAAE,CAAC;YACpD,MAAM,CAAC,IAAI,KAAK,CAAC,uDAAuD,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;YAChG,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { createHttpError, safeGetHeader } from \"builder-util-runtime\"\nimport { IncomingMessage } from \"http\"\nimport { Writable } from \"stream\"\nimport { copyData, DataSplitter, PartListDataTask } from \"./DataSplitter\"\nimport { DifferentialDownloader } from \"./DifferentialDownloader\"\nimport { Operation, OperationKind } from \"./downloadPlanBuilder\"\n\nexport function executeTasksUsingMultipleRangeRequests(\n differentialDownloader: DifferentialDownloader,\n tasks: Array<Operation>,\n out: Writable,\n oldFileFd: number,\n reject: (error: Error) => void\n): (taskOffset: number) => void {\n const w = (taskOffset: number): void => {\n if (taskOffset >= tasks.length) {\n if (differentialDownloader.fileMetadataBuffer != null) {\n out.write(differentialDownloader.fileMetadataBuffer)\n }\n out.end()\n return\n }\n\n const nextOffset = taskOffset + 1000\n doExecuteTasks(\n differentialDownloader,\n {\n tasks,\n start: taskOffset,\n end: Math.min(tasks.length, nextOffset),\n oldFileFd,\n },\n out,\n () => w(nextOffset),\n reject\n )\n }\n return w\n}\n\nfunction doExecuteTasks(differentialDownloader: DifferentialDownloader, options: PartListDataTask, out: Writable, resolve: () => void, reject: (error: Error) => void): void {\n let ranges = \"bytes=\"\n let partCount = 0\n let grandTotalBytes = 0\n const partIndexToTaskIndex = new Map<number, number>()\n const partIndexToLength: Array<number> = []\n for (let i = options.start; i < options.end; i++) {\n const task = options.tasks[i]\n if (task.kind === OperationKind.DOWNLOAD) {\n ranges += `${task.start}-${task.end - 1}, `\n partIndexToTaskIndex.set(partCount, i)\n partCount++\n partIndexToLength.push(task.end - task.start)\n grandTotalBytes += task.end - task.start\n }\n }\n\n if (partCount <= 1) {\n // the only remote range - copy\n const w = (index: number): void => {\n if (index >= options.end) {\n resolve()\n return\n }\n\n const task = options.tasks[index++]\n\n if (task.kind === OperationKind.COPY) {\n copyData(task, out, options.oldFileFd, reject, () => w(index))\n } else {\n const requestOptions = differentialDownloader.createRequestOptions()\n requestOptions.headers!.Range = `bytes=${task.start}-${task.end - 1}`\n const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {\n response.on(\"error\", reject)\n\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n response.pipe(out, {\n end: false,\n })\n response.once(\"end\", () => w(index))\n })\n differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n }\n }\n\n w(options.start)\n return\n }\n\n const requestOptions = differentialDownloader.createRequestOptions()\n requestOptions.headers!.Range = ranges.substring(0, ranges.length - 2)\n const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n const contentType = safeGetHeader(response, \"content-type\")\n const m = /^multipart\\/.+?\\s*;\\s*boundary=(?:\"([^\"]+)\"|([^\\s\";]+))\\s*$/i.exec(contentType)\n if (m == null) {\n reject(new Error(`Content-Type \"multipart/byteranges\" is expected, but got \"${contentType}\"`))\n return\n }\n\n const dicer = new DataSplitter(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, resolve, grandTotalBytes, differentialDownloader.options.onProgress)\n dicer.on(\"error\", reject)\n response.pipe(dicer)\n\n response.on(\"end\", () => {\n setTimeout(() => {\n request.abort()\n reject(new Error(\"Response ends without calling any handlers\"))\n }, 10000)\n })\n })\n differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n}\n\nexport function checkIsRangesSupported(response: IncomingMessage, reject: (error: Error) => void): boolean {\n // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.\n if (response.statusCode! >= 400) {\n reject(createHttpError(response))\n return false\n }\n\n if (response.statusCode !== 206) {\n const acceptRanges = safeGetHeader(response, \"accept-ranges\")\n if (acceptRanges == null || acceptRanges === \"none\") {\n reject(new Error(`Server doesn't support Accept-Ranges (response code ${response.statusCode})`))\n return false\n }\n }\n return true\n}\n"]}
|
|
1
|
+
{"version":3,"file":"multipleRangeDownloader.js","sourceRoot":"","sources":["../../src/differentialDownloader/multipleRangeDownloader.ts"],"names":[],"mappings":";;AAOA,wFA+BC;AAyGD,wDAeC;AA9JD,+DAAqE;AAGrE,iDAAyE;AAEzE,+DAAgE;AAEhE,SAAgB,sCAAsC,CACpD,sBAA8C,EAC9C,KAAuB,EACvB,GAAa,EACb,SAAiB,EACjB,MAA8B;IAE9B,MAAM,CAAC,GAAG,CAAC,UAAkB,EAAQ,EAAE;QACrC,IAAI,UAAU,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YAC/B,IAAI,sBAAsB,CAAC,kBAAkB,IAAI,IAAI,EAAE,CAAC;gBACtD,GAAG,CAAC,KAAK,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAA;YACtD,CAAC;YACD,GAAG,CAAC,GAAG,EAAE,CAAA;YACT,OAAM;QACR,CAAC;QAED,MAAM,UAAU,GAAG,UAAU,GAAG,IAAI,CAAA;QACpC,cAAc,CACZ,sBAAsB,EACtB;YACE,KAAK;YACL,KAAK,EAAE,UAAU;YACjB,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC;YACvC,SAAS;SACV,EACD,GAAG,EACH,GAAG,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,EACnB,MAAM,CACP,CAAA;IACH,CAAC,CAAA;IACD,OAAO,CAAC,CAAA;AACV,CAAC;AAED,SAAS,cAAc,CAAC,sBAA8C,EAAE,OAAyB,EAAE,GAAa,EAAE,OAAmB,EAAE,MAA8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,CAAA;gBACf,IAAI,eAAe,EAAE,CAAC;oBACpB,OAAM;gBACR,CAAC;gBACD,OAAO,CAAC,KAAK,EAAE,CAAA;gBACf,MAAM,CAAC,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC,CAAA;YACjE,CAAC,EAAE,KAAK,CAAC,CAAA;QACX,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,sBAAsB,CAAC,YAAY,CAAC,0BAA0B,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAC/E,OAAO,CAAC,GAAG,EAAE,CAAA;AACf,CAAC;AAED,SAAgB,sBAAsB,CAAC,QAAyB,EAAE,MAA8B;IAC9F,6HAA6H;IAC7H,IAAI,QAAQ,CAAC,UAAW,IAAI,GAAG,EAAE,CAAC;QAChC,MAAM,CAAC,IAAA,sCAAe,EAAC,QAAQ,CAAC,CAAC,CAAA;QACjC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,IAAA,oCAAa,EAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;QAC7D,IAAI,YAAY,IAAI,IAAI,IAAI,YAAY,KAAK,MAAM,EAAE,CAAC;YACpD,MAAM,CAAC,IAAI,KAAK,CAAC,uDAAuD,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;YAChG,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { createHttpError, safeGetHeader } from \"builder-util-runtime\"\nimport { IncomingMessage } from \"http\"\nimport { Writable } from \"stream\"\nimport { copyData, DataSplitter, PartListDataTask } from \"./DataSplitter\"\nimport { DifferentialDownloader } from \"./DifferentialDownloader\"\nimport { Operation, OperationKind } from \"./downloadPlanBuilder\"\n\nexport function executeTasksUsingMultipleRangeRequests(\n differentialDownloader: DifferentialDownloader,\n tasks: Array<Operation>,\n out: Writable,\n oldFileFd: number,\n reject: (error: Error) => void\n): (taskOffset: number) => void {\n const w = (taskOffset: number): void => {\n if (taskOffset >= tasks.length) {\n if (differentialDownloader.fileMetadataBuffer != null) {\n out.write(differentialDownloader.fileMetadataBuffer)\n }\n out.end()\n return\n }\n\n const nextOffset = taskOffset + 1000\n doExecuteTasks(\n differentialDownloader,\n {\n tasks,\n start: taskOffset,\n end: Math.min(tasks.length, nextOffset),\n oldFileFd,\n },\n out,\n () => w(nextOffset),\n reject\n )\n }\n return w\n}\n\nfunction doExecuteTasks(differentialDownloader: DifferentialDownloader, options: PartListDataTask, out: Writable, resolve: () => void, reject: (error: Error) => void): void {\n let ranges = \"bytes=\"\n let partCount = 0\n let grandTotalBytes = 0\n const partIndexToTaskIndex = new Map<number, number>()\n const partIndexToLength: Array<number> = []\n for (let i = options.start; i < options.end; i++) {\n const task = options.tasks[i]\n if (task.kind === OperationKind.DOWNLOAD) {\n ranges += `${task.start}-${task.end - 1}, `\n partIndexToTaskIndex.set(partCount, i)\n partCount++\n partIndexToLength.push(task.end - task.start)\n grandTotalBytes += task.end - task.start\n }\n }\n\n if (partCount <= 1) {\n // the only remote range - copy\n const w = (index: number): void => {\n if (index >= options.end) {\n resolve()\n return\n }\n\n const task = options.tasks[index++]\n\n if (task.kind === OperationKind.COPY) {\n copyData(task, out, options.oldFileFd, reject, () => w(index))\n } else {\n const requestOptions = differentialDownloader.createRequestOptions()\n requestOptions.headers!.Range = `bytes=${task.start}-${task.end - 1}`\n const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {\n response.on(\"error\", reject)\n\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n response.pipe(out, {\n end: false,\n })\n response.once(\"end\", () => w(index))\n })\n differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n }\n }\n\n w(options.start)\n return\n }\n\n const requestOptions = differentialDownloader.createRequestOptions()\n requestOptions.headers!.Range = ranges.substring(0, ranges.length - 2)\n const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n const contentType = safeGetHeader(response, \"content-type\")\n const m = /^multipart\\/.+?\\s*;\\s*boundary=(?:\"([^\"]+)\"|([^\\s\";]+))\\s*$/i.exec(contentType)\n if (m == null) {\n reject(new Error(`Content-Type \"multipart/byteranges\" is expected, but got \"${contentType}\"`))\n return\n }\n\n // The watchdog below only exists for a response that ends before every part was handled. It must not outlive a\n // successful batch: the next batch reuses the same `reject`, so a stale watchdog used to fail any multi-batch\n // download whose later batches took longer than the grace period.\n let isBatchFinished = false\n let watchdog: ReturnType<typeof setTimeout> | null = null\n const onBatchFinished = (): void => {\n isBatchFinished = true\n if (watchdog != null) {\n clearTimeout(watchdog)\n watchdog = null\n }\n resolve()\n }\n\n const dicer = new DataSplitter(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, onBatchFinished, grandTotalBytes, differentialDownloader.options.onProgress)\n dicer.on(\"error\", reject)\n response.pipe(dicer)\n\n response.on(\"end\", () => {\n if (isBatchFinished) {\n return\n }\n watchdog = setTimeout(() => {\n watchdog = null\n if (isBatchFinished) {\n return\n }\n request.abort()\n reject(new Error(\"Response ends without calling any handlers\"))\n }, 10000)\n })\n })\n differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n}\n\nexport function checkIsRangesSupported(response: IncomingMessage, reject: (error: Error) => void): boolean {\n // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.\n if (response.statusCode! >= 400) {\n reject(createHttpError(response))\n return false\n }\n\n if (response.statusCode !== 206) {\n const acceptRanges = safeGetHeader(response, \"accept-ranges\")\n if (acceptRanges == null || acceptRanges === \"none\") {\n reject(new Error(`Server doesn't support Accept-Ranges (response code ${response.statusCode})`))\n return false\n }\n }\n return true\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GitlabOptions, UpdateInfo } from "builder-util-runtime";
|
|
2
|
+
import { OutgoingHttpHeaders, RequestOptions } from "http";
|
|
2
3
|
import { URL } from "url";
|
|
3
4
|
import { AppUpdater } from "../AppUpdater";
|
|
4
5
|
import { ResolvedUpdateFileInfo } from "../types";
|
|
@@ -28,6 +29,7 @@ export declare class GitLabProvider extends Provider<GitlabUpdateInfo> {
|
|
|
28
29
|
*/
|
|
29
30
|
private normalizeFilename;
|
|
30
31
|
constructor(options: GitlabOptions, updater: AppUpdater, runtimeOptions: ProviderRuntimeOptions);
|
|
32
|
+
protected createRequestOptions(url: URL, headers?: OutgoingHttpHeaders | null): RequestOptions;
|
|
31
33
|
private get channel();
|
|
32
34
|
getLatestVersion(): Promise<GitlabUpdateInfo>;
|
|
33
35
|
/**
|