Skip to content

Commit 130a1c2

Browse files
committed
cleanup to use correct tmpdir
1 parent 359a7e6 commit 130a1c2

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

packages/app-builder-lib/src/asar/asarUtil.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ import { detectUnpackedDirs } from "./unpackDetector"
1616
export class AsarPackager {
1717
private readonly outFile: string
1818
private rootForAppFilesWithoutAsar!: string
19-
private readonly tmpDir = new tempFile.TmpDir()
2019
private readonly fileCopier = new FileCopier()
21-
22-
private readonly cleanup = () => {
23-
this.tmpDir.cleanupSync()
24-
}
20+
private readonly tmpDir: tempFile.TmpDir
21+
private readonly cancellationToken: CancellationToken
2522

2623
constructor(
24+
readonly packager: PlatformPackager<any>,
2725
private readonly config: {
2826
defaultDestination: string
2927
resourcePath: string
@@ -32,12 +30,12 @@ export class AsarPackager {
3230
}
3331
) {
3432
this.outFile = path.join(config.resourcePath, `app.asar`)
33+
this.tmpDir = packager.info.tempDirManager
34+
this.cancellationToken = packager.info.cancellationToken
3535
}
3636

37-
async pack(fileSets: Array<ResolvedFileSet>, packager: PlatformPackager<any>) {
38-
this.rootForAppFilesWithoutAsar = await packager.info.tempDirManager.getTempDir({ prefix: "asar-app" })
39-
const cancellationToken = packager.info.cancellationToken
40-
cancellationToken.addListener("cancel", this.cleanup)
37+
async pack(fileSets: Array<ResolvedFileSet>) {
38+
this.rootForAppFilesWithoutAsar = await this.tmpDir.getTempDir({ prefix: "asar-app" })
4139

4240
const orderedFileSets = [
4341
// Write dependencies first to minimize offset changes to asar header
@@ -47,13 +45,10 @@ export class AsarPackager {
4745
fileSets[0],
4846
].map(orderFileSet)
4947

50-
const { unpackedPaths, copiedFiles } = await this.detectAndCopy(orderedFileSets, cancellationToken)
48+
const { unpackedPaths, copiedFiles } = await this.detectAndCopy(orderedFileSets)
5149
const unpackGlob = unpackedPaths.length > 1 ? `{${unpackedPaths.join(",")}}` : unpackedPaths.pop()
5250

5351
await this.executeElectronAsar(copiedFiles, unpackGlob)
54-
55-
this.cleanup()
56-
cancellationToken.removeListener("cancel", this.cleanup)
5752
}
5853

5954
private async executeElectronAsar(copiedFiles: string[], unpackGlob: string | undefined) {
@@ -83,8 +78,8 @@ export class AsarPackager {
8378
console.log = consoleLogger
8479
}
8580

86-
private async detectAndCopy(fileSets: ResolvedFileSet[], cancellationToken: CancellationToken) {
87-
const taskManager = new AsyncTaskManager(cancellationToken)
81+
private async detectAndCopy(fileSets: ResolvedFileSet[]) {
82+
const taskManager = new AsyncTaskManager(this.cancellationToken)
8883
const unpackedPaths = new Set<string>()
8984
const copiedFiles = new Set<string>()
9085

packages/app-builder-lib/src/platformPackager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,12 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
504504
await transformFiles(transformer, fileSet)
505505
}
506506

507-
await new AsarPackager({
507+
await new AsarPackager(this, {
508508
defaultDestination,
509509
resourcePath,
510510
options: asarOptions,
511511
unpackPattern: fileMatcher?.createFilter(),
512-
}).pack(fileSets, this)
512+
}).pack(fileSets)
513513
})
514514
)
515515
}

0 commit comments

Comments
 (0)