26
26
// var mode = 438; /* mode=0666 */
27
27
28
28
var util = require ( 'util' ) ;
29
+ var pathModule = require ( 'path' ) ;
29
30
30
31
var binding = process . binding ( 'fs' ) ;
31
32
var constants = process . binding ( 'constants' ) ;
@@ -220,12 +221,13 @@ fs.open = function(path, flags, mode, callback) {
220
221
221
222
mode = modeNum ( mode , 438 /*=0666*/ ) ;
222
223
223
- binding . open ( path , stringToFlags ( flags ) , mode , callback ) ;
224
+ binding . open ( pathModule . _makeLong ( path ) , stringToFlags ( flags ) , mode ,
225
+ callback ) ;
224
226
} ;
225
227
226
228
fs . openSync = function ( path , flags , mode ) {
227
229
mode = modeNum ( mode , 438 /*=0666*/ ) ;
228
- return binding . open ( path , stringToFlags ( flags ) , mode ) ;
230
+ return binding . open ( pathModule . _makeLong ( path ) , stringToFlags ( flags ) , mode ) ;
229
231
} ;
230
232
231
233
fs . read = function ( fd , buffer , offset , length , position , callback ) {
@@ -320,11 +322,13 @@ fs.writeSync = function(fd, buffer, offset, length, position) {
320
322
} ;
321
323
322
324
fs . rename = function ( oldPath , newPath , callback ) {
323
- binding . rename ( oldPath , newPath , callback || noop ) ;
325
+ binding . rename ( pathModule . _makeLong ( oldPath ) , pathModule . _makeLong ( newPath ) ,
326
+ callback || noop ) ;
324
327
} ;
325
328
326
329
fs . renameSync = function ( oldPath , newPath ) {
327
- return binding . rename ( oldPath , newPath ) ;
330
+ return binding . rename ( pathModule . _makeLong ( oldPath ) ,
331
+ pathModule . _makeLong ( newPath ) ) ;
328
332
} ;
329
333
330
334
fs . truncate = function ( fd , len , callback ) {
@@ -336,11 +340,11 @@ fs.truncateSync = function(fd, len) {
336
340
} ;
337
341
338
342
fs . rmdir = function ( path , callback ) {
339
- binding . rmdir ( path , callback || noop ) ;
343
+ binding . rmdir ( pathModule . _makeLong ( path ) , callback || noop ) ;
340
344
} ;
341
345
342
346
fs . rmdirSync = function ( path ) {
343
- return binding . rmdir ( path ) ;
347
+ return binding . rmdir ( pathModule . _makeLong ( path ) ) ;
344
348
} ;
345
349
346
350
fs . fdatasync = function ( fd , callback ) {
@@ -361,11 +365,13 @@ fs.fsyncSync = function(fd) {
361
365
362
366
fs . mkdir = function ( path , mode , callback ) {
363
367
if ( typeof mode === 'function' ) callback = mode ;
364
- binding . mkdir ( path , modeNum ( mode , 511 /*=0777*/ ) , callback || noop ) ;
368
+ binding . mkdir ( pathModule . _makeLong ( path ) , modeNum ( mode , 511 /*=0777*/ ) ,
369
+ callback || noop ) ;
365
370
} ;
366
371
367
372
fs . mkdirSync = function ( path , mode ) {
368
- return binding . mkdir ( path , modeNum ( mode , 511 /*=0777*/ ) ) ;
373
+ return binding . mkdir ( pathModule . _makeLong ( path ) ,
374
+ modeNum ( mode , 511 /*=0777*/ ) ) ;
369
375
} ;
370
376
371
377
fs . sendfile = function ( outFd , inFd , inOffset , length , callback ) {
@@ -377,70 +383,74 @@ fs.sendfileSync = function(outFd, inFd, inOffset, length) {
377
383
} ;
378
384
379
385
fs . readdir = function ( path , callback ) {
380
- binding . readdir ( path , callback || noop ) ;
386
+ binding . readdir ( pathModule . _makeLong ( path ) , callback || noop ) ;
381
387
} ;
382
388
383
389
fs . readdirSync = function ( path ) {
384
- return binding . readdir ( path ) ;
390
+ return binding . readdir ( pathModule . _makeLong ( path ) ) ;
385
391
} ;
386
392
387
393
fs . fstat = function ( fd , callback ) {
388
394
binding . fstat ( fd , callback || noop ) ;
389
395
} ;
390
396
391
397
fs . lstat = function ( path , callback ) {
392
- binding . lstat ( path , callback || noop ) ;
398
+ binding . lstat ( pathModule . _makeLong ( path ) , callback || noop ) ;
393
399
} ;
394
400
395
401
fs . stat = function ( path , callback ) {
396
- binding . stat ( path , callback || noop ) ;
402
+ binding . stat ( pathModule . _makeLong ( path ) , callback || noop ) ;
397
403
} ;
398
404
399
405
fs . fstatSync = function ( fd ) {
400
406
return binding . fstat ( fd ) ;
401
407
} ;
402
408
403
409
fs . lstatSync = function ( path ) {
404
- return binding . lstat ( path ) ;
410
+ return binding . lstat ( pathModule . _makeLong ( path ) ) ;
405
411
} ;
406
412
407
413
fs . statSync = function ( path ) {
408
- return binding . stat ( path ) ;
414
+ return binding . stat ( pathModule . _makeLong ( path ) ) ;
409
415
} ;
410
416
411
417
fs . readlink = function ( path , callback ) {
412
- binding . readlink ( path , callback || noop ) ;
418
+ binding . readlink ( pathModule . _makeLong ( path ) , callback || noop ) ;
413
419
} ;
414
420
415
421
fs . readlinkSync = function ( path ) {
416
- return binding . readlink ( path ) ;
422
+ return binding . readlink ( pathModule . _makeLong ( path ) ) ;
417
423
} ;
418
424
419
425
fs . symlink = function ( destination , path , mode_ , callback ) {
420
426
var mode = ( typeof ( mode_ ) == 'string' ? mode_ : null ) ;
421
427
var callback_ = arguments [ arguments . length - 1 ] ;
422
428
callback = ( typeof ( callback_ ) == 'function' ? callback_ : null ) ;
423
- binding . symlink ( destination , path , mode , callback ) ;
429
+ binding . symlink ( pathModule . _makeLong ( destination ) ,
430
+ pathModule . _makeLong ( path ) , mode , callback ) ;
424
431
} ;
425
432
426
433
fs . symlinkSync = function ( destination , path , mode ) {
427
- return binding . symlink ( destination , path , mode ) ;
434
+ return binding . symlink ( pathModule . _makeLong ( destination ) ,
435
+ pathModule . _makeLong ( path ) , mode ) ;
428
436
} ;
429
437
430
438
fs . link = function ( srcpath , dstpath , callback ) {
431
- binding . link ( srcpath , dstpath , callback || noop ) ;
439
+ binding . link ( pathModule . _makeLong ( srcpath ) , pathModule . _makeLong ( dstpath ) ,
440
+ callback || noop ) ;
432
441
} ;
433
442
434
443
fs . linkSync = function ( srcpath , dstpath ) {
435
- return binding . link ( srcpath , dstpath ) ;
444
+ return binding . link ( pathModule . _makeLong ( srcpath ) ,
445
+ pathModule . _makeLong ( dstpath ) ) ;
436
446
} ;
437
447
438
448
fs . unlink = function ( path , callback ) {
439
- binding . unlink ( path , callback || noop ) ;
449
+ binding . unlink ( pathModule . _makeLong ( path ) , callback || noop ) ;
440
450
} ;
441
451
442
452
fs . unlinkSync = function ( path ) {
443
- return binding . unlink ( path ) ;
453
+ return binding . unlink ( pathModule . _makeLong ( path ) ) ;
444
454
} ;
445
455
446
456
fs . fchmod = function ( fd , mode , callback ) {
@@ -492,11 +502,11 @@ if (constants.hasOwnProperty('O_SYMLINK')) {
492
502
493
503
494
504
fs . chmod = function ( path , mode , callback ) {
495
- binding . chmod ( path , modeNum ( mode ) , callback || noop ) ;
505
+ binding . chmod ( pathModule . _makeLong ( path ) , modeNum ( mode ) , callback || noop ) ;
496
506
} ;
497
507
498
508
fs . chmodSync = function ( path , mode ) {
499
- return binding . chmod ( path , modeNum ( mode ) ) ;
509
+ return binding . chmod ( pathModule . _makeLong ( path ) , modeNum ( mode ) ) ;
500
510
} ;
501
511
502
512
if ( constants . hasOwnProperty ( 'O_SYMLINK' ) ) {
@@ -526,11 +536,11 @@ fs.fchownSync = function(fd, uid, gid) {
526
536
} ;
527
537
528
538
fs . chown = function ( path , uid , gid , callback ) {
529
- binding . chown ( path , uid , gid , callback || noop ) ;
539
+ binding . chown ( pathModule . _makeLong ( path ) , uid , gid , callback || noop ) ;
530
540
} ;
531
541
532
542
fs . chownSync = function ( path , uid , gid ) {
533
- return binding . chown ( path , uid , gid ) ;
543
+ return binding . chown ( pathModule . _makeLong ( path ) , uid , gid ) ;
534
544
} ;
535
545
536
546
// converts Date or number to a fractional UNIX timestamp
@@ -551,13 +561,13 @@ fs._toUnixTimestamp = toUnixTimestamp;
551
561
fs . utimes = function ( path , atime , mtime , callback ) {
552
562
atime = toUnixTimestamp ( atime ) ;
553
563
mtime = toUnixTimestamp ( mtime ) ;
554
- binding . utimes ( path , atime , mtime , callback || noop ) ;
564
+ binding . utimes ( pathModule . _makeLong ( path ) , atime , mtime , callback || noop ) ;
555
565
} ;
556
566
557
567
fs . utimesSync = function ( path , atime , mtime ) {
558
568
atime = toUnixTimestamp ( atime ) ;
559
569
mtime = toUnixTimestamp ( mtime ) ;
560
- binding . utimes ( path , atime , mtime ) ;
570
+ binding . utimes ( pathModule . _makeLong ( path ) , atime , mtime ) ;
561
571
} ;
562
572
563
573
fs . futimes = function ( fd , atime , mtime , callback ) {
@@ -646,7 +656,7 @@ function FSWatcher() {
646
656
util . inherits ( FSWatcher , EventEmitter ) ;
647
657
648
658
FSWatcher . prototype . start = function ( filename , persistent ) {
649
- var r = this . _handle . start ( filename , persistent ) ;
659
+ var r = this . _handle . start ( pathModule . _makeLong ( filename ) , persistent ) ;
650
660
651
661
if ( r ) {
652
662
this . _handle . close ( ) ;
@@ -703,7 +713,7 @@ util.inherits(StatWatcher, EventEmitter);
703
713
704
714
705
715
StatWatcher . prototype . start = function ( filename , persistent , interval ) {
706
- this . _handle . start ( filename , persistent , interval ) ;
716
+ this . _handle . start ( pathModule . _makeLong ( filename ) , persistent , interval ) ;
707
717
} ;
708
718
709
719
@@ -766,8 +776,7 @@ fs.unwatchFile = function(filename) {
766
776
// Not using realpath(2) because it's bad.
767
777
// See: http://insanecoding.blogspot.com/2007/11/pathmax-simply-isnt.html
768
778
769
- var path = require ( 'path' ) ,
770
- normalize = path . normalize ,
779
+ var normalize = pathModule . normalize ,
771
780
isWindows = process . platform === 'win32' ;
772
781
773
782
if ( isWindows ) {
@@ -776,7 +785,7 @@ if (isWindows) {
776
785
777
786
// windows version
778
787
fs . realpathSync = function realpathSync ( p , cache ) {
779
- p = path . resolve ( p ) ;
788
+ p = pathModule . resolve ( p ) ;
780
789
if ( cache && Object . prototype . hasOwnProperty . call ( cache , p ) ) {
781
790
return cache [ p ] ;
782
791
}
@@ -791,7 +800,7 @@ if (isWindows) {
791
800
cb = cache ;
792
801
cache = null ;
793
802
}
794
- p = path . resolve ( p ) ;
803
+ p = pathModule . resolve ( p ) ;
795
804
if ( cache && Object . prototype . hasOwnProperty . call ( cache , p ) ) {
796
805
return cb ( null , cache [ p ] ) ;
797
806
}
@@ -812,7 +821,7 @@ if (isWindows) {
812
821
// posix version
813
822
fs . realpathSync = function realpathSync ( p , cache ) {
814
823
// make p is absolute
815
- p = path . resolve ( p ) ;
824
+ p = pathModule . resolve ( p ) ;
816
825
817
826
if ( cache && Object . prototype . hasOwnProperty . call ( cache , p ) ) {
818
827
return cache [ p ] ;
@@ -865,14 +874,14 @@ if (isWindows) {
865
874
if ( ! seenLinks [ id ] ) {
866
875
fs . statSync ( base ) ;
867
876
seenLinks [ id ] = fs . readlinkSync ( base ) ;
868
- resolvedLink = path . resolve ( previous , seenLinks [ id ] ) ;
877
+ resolvedLink = pathModule . resolve ( previous , seenLinks [ id ] ) ;
869
878
// track this, if given a cache.
870
879
if ( cache ) cache [ base ] = resolvedLink ;
871
880
}
872
881
}
873
882
874
883
// resolve the link, then start over
875
- p = path . resolve ( resolvedLink , p . slice ( pos ) ) ;
884
+ p = pathModule . resolve ( resolvedLink , p . slice ( pos ) ) ;
876
885
pos = 0 ;
877
886
previous = base = current = '' ;
878
887
}
@@ -891,7 +900,7 @@ if (isWindows) {
891
900
}
892
901
893
902
// make p is absolute
894
- p = path . resolve ( p ) ;
903
+ p = pathModule . resolve ( p ) ;
895
904
896
905
if ( cache && Object . prototype . hasOwnProperty . call ( cache , p ) ) {
897
906
return cb ( null , cache [ p ] ) ;
@@ -969,15 +978,15 @@ if (isWindows) {
969
978
function gotTarget ( err , target , base ) {
970
979
if ( err ) return cb ( err ) ;
971
980
972
- var resolvedLink = path . resolve ( previous , target ) ;
981
+ var resolvedLink = pathModule . resolve ( previous , target ) ;
973
982
if ( cache ) cache [ base ] = resolvedLink ;
974
983
gotResolvedLink ( resolvedLink ) ;
975
984
}
976
985
977
986
function gotResolvedLink ( resolvedLink ) {
978
987
979
988
// resolve the link, then start over
980
- p = path . resolve ( resolvedLink , p . slice ( pos ) ) ;
989
+ p = pathModule . resolve ( resolvedLink , p . slice ( pos ) ) ;
981
990
pos = 0 ;
982
991
previous = base = current = '' ;
983
992
0 commit comments