From c3abc2e0c0c8bb8028775f1b060e292079a8275e Mon Sep 17 00:00:00 2001 From: Gregory Ray Date: Mon, 12 Dec 2016 10:03:18 -0800 Subject: [PATCH] Fixes bug affecting OSX in which 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. --- src/util/fs.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/util/fs.ts b/src/util/fs.ts index 78e0eddd64b..f9098ca651d 100644 --- a/src/util/fs.ts +++ b/src/util/fs.ts @@ -173,9 +173,13 @@ export function copyDir(src: string, destination: string, filter?: Filter, isUse const createdSourceDirs = new Set() const fileCopier = new FileCopier(isUseHardLink) + + type Link = { link: string, file: string } + const links: Array = [] + return walk(src, filter, async (file, stat, parent) => { if (stat.isSymbolicLink()) { - await symlink(await readlink(file), file.replace(src, destination)) + links.push( {"file": file, "link": await readlink(file)} ) return } @@ -189,5 +193,10 @@ export function copyDir(src: string, destination: string, filter?: Filter, isUse } await fileCopier.copy(file, file.replace(src, destination), stat) + }).then(() => { + while (links.length > 0) { + const ln = links.pop()! + symlink(ln.link, ln.file.replace(src, destination)) + } }) } \ No newline at end of file