Skip to content

Commit

Permalink
fix(electron-updater): nsis one-click per-machine auto-updating fails…
Browse files Browse the repository at this point in the history
… (Error: spawn [...].exe EACCES)

Close #3480, Close #3367
  • Loading branch information
develar committed Nov 16, 2018
1 parent 0fa9096 commit cc63141
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ export class NsisTarget extends Target {
file: log.filePath(installerPath),
archs: Array.from(this.archs.keys()).map(it => Arch[it]).join(", "),
}
const isPerMachine = options.perMachine === true
if (!this.isPortable) {
logFields.oneClick = oneClick
logFields.perMachine = isPerMachine
}
log.info(logFields, "building")

Expand All @@ -149,7 +151,7 @@ export class NsisTarget extends Target {
UNINSTALL_APP_KEY: uninstallAppKey,
PRODUCT_NAME: appInfo.productName,
PRODUCT_FILENAME: appInfo.productFilename,
APP_FILENAME: getWindowsInstallationDirName(appInfo, !oneClick || options.perMachine === true),
APP_FILENAME: getWindowsInstallationDirName(appInfo, !oneClick || isPerMachine),
APP_DESCRIPTION: appInfo.description,
VERSION: appInfo.version,

Expand Down Expand Up @@ -264,7 +266,7 @@ export class NsisTarget extends Target {
updateInfo = await createBlockmap(installerPath, this, packager, safeArtifactName)
}

if (updateInfo != null && options.perMachine === true && oneClick) {
if (updateInfo != null && isPerMachine && oneClick) {
updateInfo.isAdminRightsRequired = true
}

Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/util/packageDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Collector {
const resolved = await BluebirdPromise.map(unresolved, it => {
return this.readChildPackage(it, parentNodeModulesDir, rootDependency)
.catch(e => {
if ((e as any).code === "ENOENT") {
if ((e as NodeJS.ErrnoException).code === "ENOENT") {
return null
}
else {
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-util-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export function asArray<T>(v: null | undefined | T | Array<T>): Array<T> {

export function newError(message: string, code: string) {
const error = new Error(message);
(error as any).code = code
(error as NodeJS.ErrnoException).code = code
return error
}
2 changes: 1 addition & 1 deletion packages/builder-util/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export class InvalidConfigurationError extends Error {
constructor(message: string, code: string = "ERR_ELECTRON_BUILDER_INVALID_CONFIGURATION") {
super(message);

(this as any).code = code
(this as NodeJS.ErrnoException).code = code
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/electron-updater/src/NsisUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ export class NsisUpdater extends BaseUpdater {
}

_spawn(options.installerPath, args)
.catch(e => {
.catch((e: Error) => {
// https://github.com/electron-userland/electron-builder/issues/1129
// Node 8 sends errors: https://nodejs.org/dist/latest-v8.x/docs/api/errors.html#errors_common_system_errors
const errorCode = (e as any).code
const errorCode = (e as NodeJS.ErrnoException).code
this._logger.info(`Cannot run installer: error code: ${errorCode}, error message: "${e.message}", will be executed again using elevate if EACCES"`)
if (errorCode === "UNKNOWN" || errorCode.code === "EACCES") {
if (errorCode === "UNKNOWN" || errorCode === "EACCES") {
callUsingElevation()
}
else {
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/fileAssert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Assertions {
m = result
}
else {
m = (actualError as any).code || actualError.message
m = (actualError as NodeJS.ErrnoException).code || actualError.message

if (m.includes("HttpError: ") && m.indexOf("\n") > 0) {
m = m.substring(0, m.indexOf("\n"))
Expand Down

0 comments on commit cc63141

Please sign in to comment.