@@ -74,8 +74,6 @@ const {
74
74
ERR_INVALID_ARG_VALUE ,
75
75
} ,
76
76
AbortError,
77
- uvErrmapGet,
78
- uvException,
79
77
} = require ( 'internal/errors' ) ;
80
78
81
79
const {
@@ -402,11 +400,9 @@ function readFile(path, options, callback) {
402
400
}
403
401
404
402
function tryStatSync ( fd , isUserFd ) {
405
- const ctx = { } ;
406
- const stats = binding . fstat ( fd , false , undefined , ctx ) ;
407
- if ( ctx . errno !== undefined && ! isUserFd ) {
403
+ const stats = binding . fstat ( fd , false , undefined , true /* shouldNotThrow */ ) ;
404
+ if ( stats === undefined && ! isUserFd ) {
408
405
fs . closeSync ( fd ) ;
409
- throw uvException ( ctx ) ;
410
406
}
411
407
return stats ;
412
408
}
@@ -1614,33 +1610,21 @@ function statfs(path, options = { bigint: false }, callback) {
1614
1610
binding . statfs ( pathModule . toNamespacedPath ( path ) , options . bigint , req ) ;
1615
1611
}
1616
1612
1617
- function hasNoEntryError ( ctx ) {
1618
- if ( ctx . errno ) {
1619
- const uvErr = uvErrmapGet ( ctx . errno ) ;
1620
- return uvErr ?. [ 0 ] === 'ENOENT' ;
1621
- }
1622
-
1623
- if ( ctx . error ) {
1624
- return ctx . error . code === 'ENOENT' ;
1625
- }
1626
-
1627
- return false ;
1628
- }
1629
-
1630
1613
/**
1631
1614
* Synchronously retrieves the `fs.Stats` for
1632
1615
* the file descriptor.
1633
1616
* @param {number } fd
1634
1617
* @param {{
1635
1618
* bigint?: boolean;
1636
1619
* }} [options]
1637
- * @returns {Stats }
1620
+ * @returns {Stats | undefined }
1638
1621
*/
1639
1622
function fstatSync ( fd , options = { bigint : false } ) {
1640
1623
fd = getValidatedFd ( fd ) ;
1641
- const ctx = { fd } ;
1642
- const stats = binding . fstat ( fd , options . bigint , undefined , ctx ) ;
1643
- handleErrorFromBinding ( ctx ) ;
1624
+ const stats = binding . fstat ( fd , options . bigint , undefined , false ) ;
1625
+ if ( stats === undefined ) {
1626
+ return ;
1627
+ }
1644
1628
return getStatsFromBinding ( stats ) ;
1645
1629
}
1646
1630
@@ -1652,17 +1636,20 @@ function fstatSync(fd, options = { bigint: false }) {
1652
1636
* bigint?: boolean;
1653
1637
* throwIfNoEntry?: boolean;
1654
1638
* }} [options]
1655
- * @returns {Stats }
1639
+ * @returns {Stats | undefined }
1656
1640
*/
1657
1641
function lstatSync ( path , options = { bigint : false , throwIfNoEntry : true } ) {
1658
1642
path = getValidatedPath ( path ) ;
1659
- const ctx = { path } ;
1660
- const stats = binding . lstat ( pathModule . toNamespacedPath ( path ) ,
1661
- options . bigint , undefined , ctx ) ;
1662
- if ( options . throwIfNoEntry === false && hasNoEntryError ( ctx ) ) {
1663
- return undefined ;
1643
+ const stats = binding . lstat (
1644
+ pathModule . toNamespacedPath ( path ) ,
1645
+ options . bigint ,
1646
+ undefined ,
1647
+ options . throwIfNoEntry ,
1648
+ ) ;
1649
+
1650
+ if ( stats === undefined ) {
1651
+ return ;
1664
1652
}
1665
- handleErrorFromBinding ( ctx ) ;
1666
1653
return getStatsFromBinding ( stats ) ;
1667
1654
}
1668
1655
@@ -2665,9 +2652,10 @@ function realpathSync(p, options) {
2665
2652
2666
2653
// On windows, check that the root exists. On unix there is no need.
2667
2654
if ( isWindows ) {
2668
- const ctx = { path : base } ;
2669
- binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2670
- handleErrorFromBinding ( ctx ) ;
2655
+ const out = binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , true /* throwIfNoEntry */ ) ;
2656
+ if ( out === undefined ) {
2657
+ return ;
2658
+ }
2671
2659
knownHard . add ( base ) ;
2672
2660
}
2673
2661
@@ -2707,9 +2695,10 @@ function realpathSync(p, options) {
2707
2695
// for our internal use.
2708
2696
2709
2697
const baseLong = pathModule . toNamespacedPath ( base ) ;
2710
- const ctx = { path : base } ;
2711
- const stats = binding . lstat ( baseLong , true , undefined , ctx ) ;
2712
- handleErrorFromBinding ( ctx ) ;
2698
+ const stats = binding . lstat ( baseLong , true , undefined , true /* throwIfNoEntry */ ) ;
2699
+ if ( stats === undefined ) {
2700
+ return ;
2701
+ }
2713
2702
2714
2703
if ( ! isFileType ( stats , S_IFLNK ) ) {
2715
2704
knownHard . add ( base ) ;
@@ -2748,9 +2737,10 @@ function realpathSync(p, options) {
2748
2737
2749
2738
// On windows, check that the root exists. On unix there is no need.
2750
2739
if ( isWindows && ! knownHard . has ( base ) ) {
2751
- const ctx = { path : base } ;
2752
- binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2753
- handleErrorFromBinding ( ctx ) ;
2740
+ const out = binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , true /* throwIfNoEntry */ ) ;
2741
+ if ( out === undefined ) {
2742
+ return ;
2743
+ }
2754
2744
knownHard . add ( base ) ;
2755
2745
}
2756
2746
}
0 commit comments