@@ -57,7 +57,6 @@ const {
57
57
preprocessSymlinkDestination,
58
58
Stats,
59
59
getStatsFromBinding,
60
- getStatsFromGlobalBinding,
61
60
stringToFlags,
62
61
stringToSymlinkType,
63
62
toUnixTimestamp,
@@ -158,10 +157,10 @@ function isFd(path) {
158
157
159
158
fs . Stats = Stats ;
160
159
161
- function isFileType ( fileType ) {
160
+ function isFileType ( stats , fileType ) {
162
161
// Use stats array directly to avoid creating an fs.Stats instance just for
163
162
// our internal use.
164
- return ( statValues [ 1 /* mode */ ] & S_IFMT ) === fileType ;
163
+ return ( stats [ 1 /* mode */ ] & S_IFMT ) === fileType ;
165
164
}
166
165
167
166
// Don't allow mode to accidentally be overwritten.
@@ -330,15 +329,15 @@ function readFileAfterOpen(err, fd) {
330
329
binding . fstat ( fd , req ) ;
331
330
}
332
331
333
- function readFileAfterStat ( err ) {
332
+ function readFileAfterStat ( err , stats ) {
334
333
var context = this . context ;
335
334
336
335
if ( err )
337
336
return context . close ( err ) ;
338
337
339
338
var size ;
340
- if ( isFileType ( S_IFREG ) )
341
- size = context . size = statValues [ 8 ] ;
339
+ if ( isFileType ( stats , S_IFREG ) )
340
+ size = context . size = stats [ 8 ] ;
342
341
else
343
342
size = context . size = 0 ;
344
343
@@ -411,11 +410,12 @@ function readFileAfterClose(err) {
411
410
412
411
function tryStatSync ( fd , isUserFd ) {
413
412
const ctx = { } ;
414
- binding . fstat ( fd , undefined , ctx ) ;
413
+ const stats = binding . fstat ( fd , undefined , ctx ) ;
415
414
if ( ctx . errno !== undefined && ! isUserFd ) {
416
415
fs . closeSync ( fd ) ;
417
416
throw errors . uvException ( ctx ) ;
418
417
}
418
+ return stats ;
419
419
}
420
420
421
421
function tryCreateBuffer ( size , fd , isUserFd ) {
@@ -450,10 +450,10 @@ fs.readFileSync = function(path, options) {
450
450
var isUserFd = isFd ( path ) ; // file descriptor ownership
451
451
var fd = isUserFd ? path : fs . openSync ( path , options . flag || 'r' , 0o666 ) ;
452
452
453
- tryStatSync ( fd , isUserFd ) ;
453
+ const stats = tryStatSync ( fd , isUserFd ) ;
454
454
var size ;
455
- if ( isFileType ( S_IFREG ) )
456
- size = statValues [ 8 ] ;
455
+ if ( isFileType ( stats , S_IFREG ) )
456
+ size = stats [ 8 ] ;
457
457
else
458
458
size = 0 ;
459
459
var pos = 0 ;
@@ -890,27 +890,29 @@ fs.stat = function(path, callback) {
890
890
fs . fstatSync = function ( fd ) {
891
891
validateUint32 ( fd , 'fd' ) ;
892
892
const ctx = { fd } ;
893
- binding . fstat ( fd , undefined , ctx ) ;
893
+ const stats = binding . fstat ( fd , undefined , ctx ) ;
894
894
handleErrorFromBinding ( ctx ) ;
895
- return getStatsFromGlobalBinding ( ) ;
895
+ return getStatsFromBinding ( stats ) ;
896
896
} ;
897
897
898
898
fs . lstatSync = function ( path ) {
899
899
path = getPathFromURL ( path ) ;
900
900
validatePath ( path ) ;
901
901
const ctx = { path } ;
902
- binding . lstat ( pathModule . toNamespacedPath ( path ) , undefined , ctx ) ;
902
+ const stats = binding . lstat ( pathModule . toNamespacedPath ( path ) ,
903
+ undefined , ctx ) ;
903
904
handleErrorFromBinding ( ctx ) ;
904
- return getStatsFromGlobalBinding ( ) ;
905
+ return getStatsFromBinding ( stats ) ;
905
906
} ;
906
907
907
908
fs . statSync = function ( path ) {
908
909
path = getPathFromURL ( path ) ;
909
910
validatePath ( path ) ;
910
911
const ctx = { path } ;
911
- binding . stat ( pathModule . toNamespacedPath ( path ) , undefined , ctx ) ;
912
+ const stats = binding . stat ( pathModule . toNamespacedPath ( path ) ,
913
+ undefined , ctx ) ;
912
914
handleErrorFromBinding ( ctx ) ;
913
- return getStatsFromGlobalBinding ( ) ;
915
+ return getStatsFromBinding ( stats ) ;
914
916
} ;
915
917
916
918
fs . readlink = function ( path , options , callback ) {
@@ -1439,7 +1441,7 @@ function StatWatcher() {
1439
1441
this . _handle . onchange = function ( newStatus , stats ) {
1440
1442
if ( oldStatus === - 1 &&
1441
1443
newStatus === - 1 &&
1442
- statValues [ 2 /* new nlink */ ] === statValues [ 16 /* old nlink */ ] ) return ;
1444
+ stats [ 2 /* new nlink */ ] === stats [ 16 /* old nlink */ ] ) return ;
1443
1445
1444
1446
oldStatus = newStatus ;
1445
1447
self . emit ( 'change' , getStatsFromBinding ( stats ) ,
@@ -1666,7 +1668,8 @@ fs.realpathSync = function realpathSync(p, options) {
1666
1668
1667
1669
// continue if not a symlink, break if a pipe/socket
1668
1670
if ( knownHard [ base ] || ( cache && cache . get ( base ) === base ) ) {
1669
- if ( isFileType ( S_IFIFO ) || isFileType ( S_IFSOCK ) ) {
1671
+ if ( isFileType ( statValues , S_IFIFO ) ||
1672
+ isFileType ( statValues , S_IFSOCK ) ) {
1670
1673
break ;
1671
1674
}
1672
1675
continue ;
@@ -1682,10 +1685,10 @@ fs.realpathSync = function realpathSync(p, options) {
1682
1685
1683
1686
var baseLong = pathModule . toNamespacedPath ( base ) ;
1684
1687
const ctx = { path : base } ;
1685
- binding . lstat ( baseLong , undefined , ctx ) ;
1688
+ const stats = binding . lstat ( baseLong , undefined , ctx ) ;
1686
1689
handleErrorFromBinding ( ctx ) ;
1687
1690
1688
- if ( ! isFileType ( S_IFLNK ) ) {
1691
+ if ( ! isFileType ( stats , S_IFLNK ) ) {
1689
1692
knownHard [ base ] = true ;
1690
1693
if ( cache ) cache . set ( base , base ) ;
1691
1694
continue ;
@@ -1696,8 +1699,8 @@ fs.realpathSync = function realpathSync(p, options) {
1696
1699
var linkTarget = null ;
1697
1700
var id ;
1698
1701
if ( ! isWindows ) {
1699
- var dev = statValues [ 0 ] . toString ( 32 ) ;
1700
- var ino = statValues [ 7 ] . toString ( 32 ) ;
1702
+ var dev = stats [ 0 ] . toString ( 32 ) ;
1703
+ var ino = stats [ 7 ] . toString ( 32 ) ;
1701
1704
id = `${ dev } :${ ino } ` ;
1702
1705
if ( seenLinks [ id ] ) {
1703
1706
linkTarget = seenLinks [ id ] ;
@@ -1778,7 +1781,7 @@ fs.realpath = function realpath(p, options, callback) {
1778
1781
1779
1782
// On windows, check that the root exists. On unix there is no need.
1780
1783
if ( isWindows && ! knownHard [ base ] ) {
1781
- fs . lstat ( base , function ( err ) {
1784
+ fs . lstat ( base , function ( err , stats ) {
1782
1785
if ( err ) return callback ( err ) ;
1783
1786
knownHard [ base ] = true ;
1784
1787
LOOP ( ) ;
@@ -1811,7 +1814,8 @@ fs.realpath = function realpath(p, options, callback) {
1811
1814
1812
1815
// continue if not a symlink, break if a pipe/socket
1813
1816
if ( knownHard [ base ] ) {
1814
- if ( isFileType ( S_IFIFO ) || isFileType ( S_IFSOCK ) ) {
1817
+ if ( isFileType ( statValues , S_IFIFO ) ||
1818
+ isFileType ( statValues , S_IFSOCK ) ) {
1815
1819
return callback ( null , encodeRealpathResult ( p , options ) ) ;
1816
1820
}
1817
1821
return process . nextTick ( LOOP ) ;
@@ -1820,14 +1824,11 @@ fs.realpath = function realpath(p, options, callback) {
1820
1824
return fs . lstat ( base , gotStat ) ;
1821
1825
}
1822
1826
1823
- function gotStat ( err ) {
1827
+ function gotStat ( err , stats ) {
1824
1828
if ( err ) return callback ( err ) ;
1825
1829
1826
- // Use stats array directly to avoid creating an fs.Stats instance just for
1827
- // our internal use.
1828
-
1829
1830
// if not a symlink, skip to the next path part
1830
- if ( ! isFileType ( S_IFLNK ) ) {
1831
+ if ( ! stats . isSymbolicLink ( ) ) {
1831
1832
knownHard [ base ] = true ;
1832
1833
return process . nextTick ( LOOP ) ;
1833
1834
}
@@ -1837,8 +1838,8 @@ fs.realpath = function realpath(p, options, callback) {
1837
1838
// dev/ino always return 0 on windows, so skip the check.
1838
1839
let id ;
1839
1840
if ( ! isWindows ) {
1840
- var dev = statValues [ 0 ] . toString ( 32 ) ;
1841
- var ino = statValues [ 7 ] . toString ( 32 ) ;
1841
+ var dev = stats . dev . toString ( 32 ) ;
1842
+ var ino = stats . ino . toString ( 32 ) ;
1842
1843
id = `${ dev } :${ ino } ` ;
1843
1844
if ( seenLinks [ id ] ) {
1844
1845
return gotTarget ( null , seenLinks [ id ] , base ) ;
0 commit comments