From 20d3111870362e98a1255e41fd335a89bd4902ae Mon Sep 17 00:00:00 2001 From: Mike Maietta Date: Mon, 4 Nov 2024 07:48:05 -0800 Subject: [PATCH] got all globTest working --- packages/app-builder-lib/src/asar/asarUtil.ts | 58 ++++++------------- test/snapshots/globTest.js.snap | 8 --- 2 files changed, 19 insertions(+), 47 deletions(-) diff --git a/packages/app-builder-lib/src/asar/asarUtil.ts b/packages/app-builder-lib/src/asar/asarUtil.ts index af46fae0d31..f07e5726f73 100644 --- a/packages/app-builder-lib/src/asar/asarUtil.ts +++ b/packages/app-builder-lib/src/asar/asarUtil.ts @@ -1,9 +1,7 @@ -import BluebirdPromise from "bluebird-lst" - import { CreateOptions, createPackageWithOptions } from "@electron/asar" import { AsyncTaskManager, log } from "builder-util" import { CancellationToken } from "builder-util-runtime" -import { CONCURRENCY, copyDir, DO_NOT_USE_HARD_LINKS, FileCopier, Filter, FilterStats, Link, MAX_FILE_REQUESTS } from "builder-util/out/fs" +import { DO_NOT_USE_HARD_LINKS, FileCopier, Filter, Link, MAX_FILE_REQUESTS } from "builder-util/out/fs" import * as fsNode from "fs" import * as fs from "fs-extra" import * as path from "path" @@ -101,6 +99,7 @@ export class AsarPackager { if (!stat.isFile() && !stat.isSymbolicLink()) { return } + copiedFiles.add(destFile) const dir = path.dirname(destFile) if (!createdSourceDirs.has(dir)) { @@ -108,17 +107,9 @@ export class AsarPackager { createdSourceDirs.add(dir) } - copiedFiles.add(destFile) if (transformedData != null) { return fs.writeFile(destFile, transformedData, { mode: stat.mode }) } - if (stat.isFile()) { - return this.fileCopier.copy(file, destFile, stat) - } - let link = await readlink(file) - if (path.isAbsolute(link)) { - link = path.relative(path.dirname(file), link) - } const realPathFile = await fs.realpath(file) const realPathRelative = path.relative(fileSet.src, realPathFile) @@ -128,6 +119,17 @@ export class AsarPackager { throw new Error(`Cannot copy file (${path.basename(file)}) symlinked to file (${path.basename(realPathFile)}) outside the package as that violates asar security integrity`) } + // not a symlink + if (file === realPathFile) { + return this.fileCopier.copy(file, destFile, stat) + } + + // must be a symlink + let link = await readlink(file) + if (path.isAbsolute(link)) { + link = path.relative(path.dirname(file), link) + } + links.push({ file: destFile, link }) } @@ -162,40 +164,18 @@ export class AsarPackager { await taskManager.awaitTasks() for (const it of links) { // taskManager.addTask( - await symlink(it.link, it.file, symlinkType) - // ) - if (taskManager.tasks.length > MAX_FILE_REQUESTS) { - await taskManager.awaitTasks() - } + await symlink(it.link, it.file, symlinkType) + // ) + if (taskManager.tasks.length > MAX_FILE_REQUESTS) { + await taskManager.awaitTasks() } - await taskManager.awaitTasks() + } + await taskManager.awaitTasks() return { unpackedPaths: Array.from(unpackedPaths), copiedFiles: Array.from(copiedFiles), } } - - private async copyFileOrData(data: string | Buffer | undefined, source: string, destination: string, stat: fs.Stats) { - // const sourceStat = stat || fs.statSync(source) - // if (sourceStat.isSymbolicLink()) { - // return copyDir(source, destination) - // } - // if (sourceStat.isSymbolicLink()) { - // const link = fs.readlinkSync(source) - // // const symlinkTarget = path.resolve(this.rootForAppFilesWithoutAsar, realPathRelative) - // // await this.copyFileOrData(undefined, source, symlinkTarget, stat) - // const target = path.relative(path.dirname(destination), link) - // fsNode.symlinkSync(target, destination) - // return - // } - await fs.mkdir(path.dirname(destination), { recursive: true }) - if (data != null) { - return fs.writeFile(destination, data, { mode: stat.mode }) - } else { - // return fs.copyFile(source, destination) - return this.fileCopier.copy(source, destination, stat) - } - } } function orderFileSet(fileSet: ResolvedFileSet): ResolvedFileSet { diff --git a/test/snapshots/globTest.js.snap b/test/snapshots/globTest.js.snap index 5b4efb7b68e..8464b2515aa 100644 --- a/test/snapshots/globTest.js.snap +++ b/test/snapshots/globTest.js.snap @@ -9836,14 +9836,6 @@ exports[`local node module with file protocol 1`] = ` } `; -exports[`outside link 1`] = ` -{ - "linux": [], -} -`; - -exports[`outside link 2`] = `undefined`; - exports[`symlinks everywhere w/ static framework 1`] = ` { "linux": [],