@@ -7,6 +7,15 @@ var mkdirp = require('mkdirp')
7
7
var rimraf = require ( 'rimraf' )
8
8
var assert = require ( 'assert' )
9
9
var map = require ( 'map-limit' )
10
+ var os = require ( 'os' )
11
+
12
+ // Use junctions on Windows < Vista (6.0),
13
+ // Vista and later support regular symlinks.
14
+ if ( os . platform ( ) == 'win32' && parseInt ( os . release ( ) ) < 6 ) {
15
+ var symlinkType = 'junction'
16
+ } else {
17
+ symlinkType = 'dir'
18
+ }
10
19
11
20
module . exports = function linklocal ( dirpath , _done ) {
12
21
function done ( err , items ) {
@@ -280,9 +289,16 @@ function linkLinks(links, done) {
280
289
map ( links , Infinity , function ( link , next ) {
281
290
mkdirp ( path . dirname ( link . from ) , function ( err ) {
282
291
if ( err && err . code !== 'EEXISTS' ) return next ( err )
292
+
283
293
var from = link . from
284
- var to = path . relative ( path . dirname ( link . from ) , link . to )
285
- fs . symlink ( to , from , 'junction' , function ( err ) {
294
+ var to = link . to
295
+
296
+ // Junction points can't be relative
297
+ if ( symlinkType !== 'junction' ) {
298
+ to = path . relative ( path . dirname ( from ) , to )
299
+ }
300
+
301
+ fs . symlink ( to , from , symlinkType , function ( err ) {
286
302
if ( err ) return next ( new Error ( 'Error linking ' + from + ' to ' + to + ':\n' + err . message ) )
287
303
next ( null , link )
288
304
} )
0 commit comments