Skip to content

Commit

Permalink
got all globTest working
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaietta committed Nov 4, 2024
1 parent 75b6d0a commit 20d3111
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 47 deletions.
58 changes: 19 additions & 39 deletions packages/app-builder-lib/src/asar/asarUtil.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -101,24 +99,17 @@ export class AsarPackager {
if (!stat.isFile() && !stat.isSymbolicLink()) {
return
}
copiedFiles.add(destFile)

const dir = path.dirname(destFile)
if (!createdSourceDirs.has(dir)) {
await mkdir(dir, { recursive: true })
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)
Expand All @@ -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 })
}

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 0 additions & 8 deletions test/snapshots/globTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down

0 comments on commit 20d3111

Please sign in to comment.