@@ -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 new UVException ( ctx ) ;
410
406
}
411
407
return stats ;
412
408
}
@@ -1616,33 +1612,21 @@ function statfs(path, options = { bigint: false }, callback) {
1616
1612
binding . statfs ( pathModule . toNamespacedPath ( path ) , options . bigint , req ) ;
1617
1613
}
1618
1614
1619
- function hasNoEntryError ( ctx ) {
1620
- if ( ctx . errno ) {
1621
- const uvErr = uvErrmapGet ( ctx . errno ) ;
1622
- return uvErr ?. [ 0 ] === 'ENOENT' ;
1623
- }
1624
-
1625
- if ( ctx . error ) {
1626
- return ctx . error . code === 'ENOENT' ;
1627
- }
1628
-
1629
- return false ;
1630
- }
1631
-
1632
1615
/**
1633
1616
* Synchronously retrieves the `fs.Stats` for
1634
1617
* the file descriptor.
1635
1618
* @param {number } fd
1636
1619
* @param {{
1637
1620
* bigint?: boolean;
1638
1621
* }} [options]
1639
- * @returns {Stats }
1622
+ * @returns {Stats | undefined }
1640
1623
*/
1641
1624
function fstatSync ( fd , options = { bigint : false } ) {
1642
1625
fd = getValidatedFd ( fd ) ;
1643
- const ctx = { fd } ;
1644
- const stats = binding . fstat ( fd , options . bigint , undefined , ctx ) ;
1645
- handleErrorFromBinding ( ctx ) ;
1626
+ const stats = binding . fstat ( fd , options . bigint , undefined , false ) ;
1627
+ if ( stats === undefined ) {
1628
+ return ;
1629
+ }
1646
1630
return getStatsFromBinding ( stats ) ;
1647
1631
}
1648
1632
@@ -1654,17 +1638,20 @@ function fstatSync(fd, options = { bigint: false }) {
1654
1638
* bigint?: boolean;
1655
1639
* throwIfNoEntry?: boolean;
1656
1640
* }} [options]
1657
- * @returns {Stats }
1641
+ * @returns {Stats | undefined }
1658
1642
*/
1659
1643
function lstatSync ( path , options = { bigint : false , throwIfNoEntry : true } ) {
1660
1644
path = getValidatedPath ( path ) ;
1661
- const ctx = { path } ;
1662
- const stats = binding . lstat ( pathModule . toNamespacedPath ( path ) ,
1663
- options . bigint , undefined , ctx ) ;
1664
- if ( options . throwIfNoEntry === false && hasNoEntryError ( ctx ) ) {
1665
- return undefined ;
1645
+ const stats = binding . lstat (
1646
+ pathModule . toNamespacedPath ( path ) ,
1647
+ options . bigint ,
1648
+ undefined ,
1649
+ options . throwIfNoEntry ,
1650
+ ) ;
1651
+
1652
+ if ( stats === undefined ) {
1653
+ return ;
1666
1654
}
1667
- handleErrorFromBinding ( ctx ) ;
1668
1655
return getStatsFromBinding ( stats ) ;
1669
1656
}
1670
1657
@@ -2667,9 +2654,10 @@ function realpathSync(p, options) {
2667
2654
2668
2655
// On windows, check that the root exists. On unix there is no need.
2669
2656
if ( isWindows ) {
2670
- const ctx = { path : base } ;
2671
- binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2672
- handleErrorFromBinding ( ctx ) ;
2657
+ const out = binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , true /* throwIfNoEntry */ ) ;
2658
+ if ( out === undefined ) {
2659
+ return ;
2660
+ }
2673
2661
knownHard . add ( base ) ;
2674
2662
}
2675
2663
@@ -2709,9 +2697,10 @@ function realpathSync(p, options) {
2709
2697
// for our internal use.
2710
2698
2711
2699
const baseLong = pathModule . toNamespacedPath ( base ) ;
2712
- const ctx = { path : base } ;
2713
- const stats = binding . lstat ( baseLong , true , undefined , ctx ) ;
2714
- handleErrorFromBinding ( ctx ) ;
2700
+ const stats = binding . lstat ( baseLong , true , undefined , true /* throwIfNoEntry */ ) ;
2701
+ if ( stats === undefined ) {
2702
+ return ;
2703
+ }
2715
2704
2716
2705
if ( ! isFileType ( stats , S_IFLNK ) ) {
2717
2706
knownHard . add ( base ) ;
@@ -2750,9 +2739,10 @@ function realpathSync(p, options) {
2750
2739
2751
2740
// On windows, check that the root exists. On unix there is no need.
2752
2741
if ( isWindows && ! knownHard . has ( base ) ) {
2753
- const ctx = { path : base } ;
2754
- binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2755
- handleErrorFromBinding ( ctx ) ;
2742
+ const out = binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , true /* throwIfNoEntry */ ) ;
2743
+ if ( out === undefined ) {
2744
+ return ;
2745
+ }
2756
2746
knownHard . add ( base ) ;
2757
2747
}
2758
2748
}
0 commit comments