Skip to content

Commit

Permalink
Normalize paths before comparing them in symlinkWithOverwrite
Browse files Browse the repository at this point in the history
In windows, source is in posix format and missing a trailing slash, causing the symlink to always be recreated.
  • Loading branch information
zodern committed Jan 1, 2019
1 parent c2ef377 commit 9c3385f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tools/fs/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ 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) {
export const symlinkWithOverwrite = Profile("files.symlinkWithOverwrite", function symlinkWithOverwrite(source, target) {
const args = [source, target];

if (process.platform === "win32") {
Expand All @@ -543,8 +543,12 @@ export function symlinkWithOverwrite(source, target) {
files.symlink(...args);
} catch (e) {
if (e.code === "EEXIST") {
function normalizePath (path) {
return files.convertToOSPath(path).replace(/[\/\\]$/, "")
}

if (files.lstat(target).isSymbolicLink() &&
files.readlink(target) === source) {
normalizePath(files.readlink(target)) === normalizePath(source)) {
// If the target already points to the desired source, we don't
// need to do anything.
return;
Expand All @@ -556,7 +560,7 @@ export function symlinkWithOverwrite(source, target) {
throw e;
}
}
}
})

/**
* Get every path in a directory recursively, treating symlinks as files
Expand Down

0 comments on commit 9c3385f

Please sign in to comment.