Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: check asar existence and integrity #401

Merged
merged 1 commit into from
May 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { copy } from "fs-extra-p"
import { statOrNull, use } from "./util"
import { Packager } from "./packager"
import deepAssign = require("deep-assign")
import { statFile } from "asar"
import { listPackage, statFile } from "asar"
import ElectronPackagerOptions = ElectronPackager.ElectronPackagerOptions

//noinspection JSUnusedLocalSymbols
Expand Down Expand Up @@ -201,13 +201,16 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return this.devMetadata.build["build-version"] || process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM || process.env.BUILD_NUMBER
}

private getResourcesDir(appOutDir: string): string {
return this.platform === Platform.OSX ? this.getOSXResourcesDir(appOutDir) : path.join(appOutDir, "resources")
}

private getOSXResourcesDir(appOutDir: string): string {
return path.join(appOutDir, this.appName + ".app", "Contents", "Resources")
}

private async statFileInPackage(appOutDir: string, packageFile: string, isAsar: boolean): Promise<any> {
private async statFileInPackage(resourcesDir: string, packageFile: string, isAsar: boolean): Promise<any> {
const relativeFile = path.relative(this.info.appDir, path.resolve(this.info.appDir, packageFile))
const resourcesDir = this.platform === Platform.OSX ? this.getOSXResourcesDir(appOutDir) : path.join(appOutDir, "resources")
if (isAsar) {
try {
return statFile(path.join(resourcesDir, "app.asar"), relativeFile) != null
Expand All @@ -223,17 +226,38 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}
}

private async sanityCheckPackage(appOutDir: string, asar: boolean): Promise<any> {
private async sanityCheckAsar(asarFile: string): Promise<any> {
const outStat = await statOrNull(asarFile)

if (outStat == null) {
throw new Error(`Package file ${asarFile} was not created.`)
}

try {
listPackage(asarFile)
}
catch (e) {
throw new Error(`Package file ${asarFile} is corrupted.`)
Copy link
Member

Choose a reason for hiding this comment

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

Is it real case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#371 suggests that it is real. Haven't been able to reproduce.

}
}

private async sanityCheckPackage(appOutDir: string, isAsar: boolean): Promise<any> {
const outStat = await statOrNull(appOutDir)

if (outStat == null) {
throw new Error(`Output directory ${appOutDir} does not exists. Seems like a wrong configuration.`)
}
else if (!outStat.isDirectory()) {
throw new Error(`Output directory ${appOutDir} is not a directory. Seems like a wrong configuration.`)
}

const resourcesDir = this.getResourcesDir(appOutDir)
if (isAsar) {
await this.sanityCheckAsar(path.join(resourcesDir, "app.asar"))
}

const mainFile = this.metadata.main || "index.js"
const mainFileExists = await this.statFileInPackage(appOutDir, mainFile, asar)
const mainFileExists = await this.statFileInPackage(resourcesDir, mainFile, isAsar)
if (!mainFileExists) {
throw new Error(`Application entry file ${mainFile} could not be found in package. Seems like a wrong configuration.`)
}
Expand Down