Skip to content

Commit

Permalink
Don't relink things that are already linked right
Browse files Browse the repository at this point in the history
  • Loading branch information
iarna committed Jun 26, 2015
1 parent 67ca1e6 commit 574059c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/utils/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ var fs = require("graceful-fs")
function linkIfExists (from, to, gently, cb) {
fs.stat(from, function (er) {
if (er) return cb()
link(from, to, gently, cb)
fs.readlink(to, function (er, fromOnDisk) {
// if the link already exists and matches what we would do,
// we don't need to do anything
if (!er) {
var toDir = path.dirname(to)
var absoluteFrom = path.resolve(toDir, from)
var absoluteFromOnDisk = path.resolve(toDir, fromOnDisk)
if (absoluteFrom === absoluteFromOnDisk) return cb()
}
link(from, to, gently, cb)
})
})
}

Expand Down

0 comments on commit 574059c

Please sign in to comment.