Skip to content

Commit

Permalink
fix: ENOENT for symlinks because directory was not created
Browse files Browse the repository at this point in the history
Closes #1002, #998
  • Loading branch information
develar committed Dec 13, 2016
1 parent a457d0d commit 76de8f7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
1 change: 0 additions & 1 deletion .idea/rc-producer.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions src/util/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,9 @@ export function copyDir(src: string, destination: string, filter?: Filter, isUse

const createdSourceDirs = new Set<string>()
const fileCopier = new FileCopier(isUseHardLink)
return walk(src, filter, async (file, stat, parent) => {
if (stat.isSymbolicLink()) {
await symlink(await readlink(file), file.replace(src, destination))
return
}

if (!stat.isFile()) {
const links: Array<Link> = []
return walk(src, filter, async(file, stat, parent) => {
if (!stat.isFile() && !stat.isSymbolicLink()) {
return
}

Expand All @@ -188,6 +184,18 @@ export function copyDir(src: string, destination: string, filter?: Filter, isUse
createdSourceDirs.add(parent)
}

await fileCopier.copy(file, file.replace(src, destination), stat)
const destFile = file.replace(src, destination)
if (stat.isFile()) {
await fileCopier.copy(file, destFile, stat)
}
else {
links.push({"file": destFile, "link": await readlink(file)})
}
})
.then(() => BluebirdPromise.map(links, it => symlink(it.link, it.file), CONCURRENCY))
}

interface Link {
readonly link: string,
readonly file: string
}
21 changes: 20 additions & 1 deletion test/src/filesTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectedWinContents } from "./helpers/expectedContents"
import { outputFile, stat, readFile } from "fs-extra-p"
import { outputFile, stat, symlink, readFile } from "fs-extra-p"
import { assertPack, modifyPackageJson, getPossiblePlatforms, app } from "./helpers/packTester"
import BluebirdPromise from "bluebird-lst-c"
import * as path from "path"
Expand All @@ -8,6 +8,8 @@ import { Platform, DIR_TARGET } from "out"
import pathSorter from "path-sort"
import Mode from "stat-mode"
import { Permissions } from "stat-mode"
import { TmpDir } from "out/util/tmp"
import { copyDir } from "out/util/fs"

test.ifDevOrLinuxCi("files", app({
targets: Platform.LINUX.createTarget(DIR_TARGET),
Expand Down Expand Up @@ -179,6 +181,23 @@ test("extraResources - one-package", () => {
})
})

// https://github.com/electron-userland/electron-builder/pull/998
// copyDir walks to a symlink referencing a file that has not yet been copied by postponing the linking step until after the full walk is complete
test("postpone symlink", async () => {
const tmpDir = new TmpDir()
const source = await tmpDir.getTempFile("src")
const aSourceFile = path.join(source, "z", "Z")
const bSourceFileLink = path.join(source, "B")
await outputFile(aSourceFile, "test")
await symlink(aSourceFile, bSourceFileLink)


const dest = await tmpDir.getTempFile("dest")
await copyDir(source, dest)

await tmpDir.cleanup()
})

async function allCan(file: string, execute: Boolean) {
const mode = new Mode(await stat(file))

Expand Down

0 comments on commit 76de8f7

Please sign in to comment.