]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/utils/link.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / lib / utils / link.js
1
2 module.exports = link
3 link.ifExists = linkIfExists
4
5 var fs = require("graceful-fs")
6   , chain = require("slide").chain
7   , mkdir = require("mkdirp")
8   , rm = require("./gently-rm.js")
9   , path = require("path")
10   , npm = require("../npm.js")
11
12 function linkIfExists (from, to, gently, cb) {
13   fs.stat(from, function (er) {
14     if (er) return cb()
15     link(from, to, gently, cb)
16   })
17 }
18
19 function link (from, to, gently, abs, cb) {
20   if (typeof cb !== "function") cb = abs, abs = false
21   if (typeof cb !== "function") cb = gently, gently = null
22   if (npm.config.get("force")) gently = false
23
24   to = path.resolve(to)
25   var target = from = path.resolve(from)
26   if (!abs && process.platform !== "win32") {
27     // junctions on windows must be absolute
28     target = path.relative(path.dirname(to), from)
29     // if there is no folder in common, then it will be much
30     // longer, and using a relative link is dumb.
31     if (target.length >= from.length) target = from
32   }
33
34   chain
35     ( [ [fs, "stat", from]
36       , [rm, to, gently]
37       , [mkdir, path.dirname(to)]
38       , [fs, "symlink", target, to, "junction"] ]
39     , cb)
40 }