Skip to content

Commit

Permalink
Fix creating symlinks on Windows April 2018 Update (meteor#9887)
Browse files Browse the repository at this point in the history
  • Loading branch information
zodern authored and Ben Newman committed May 26, 2018
1 parent f193979 commit cd4f8d4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tools/fs/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,19 +520,23 @@ files.cp_r = function(from, to, options = {}) {
// create a symlink, overwriting the target link, file, or directory
// if it exists
export function symlinkWithOverwrite(source, target) {
const args = [source, target];

if (process.platform === "win32") {
const absoluteSource = files.pathResolve(target, source);

if (files.stat(absoluteSource).isDirectory()) {
args[2] = "junction";
}
}

try {
files.symlink(source, target);
files.symlink(...args);
} catch (e) {
if (e.code === "EEXIST") {
// overwrite existing link, file, or directory
files.rm_recursive(target);
files.symlink(source, target);
} else if (e.code === "EPERM" &&
process.platform === "win32") {
files.rm_recursive(target);
// This will work only if source refers to a directory, but that's a
// chance worth taking.
files.symlink(source, target, "junction");
files.symlink(...args);
} else {
throw e;
}
Expand Down

0 comments on commit cd4f8d4

Please sign in to comment.