@@ -141,7 +141,7 @@ const {
141
141
validateObject,
142
142
validateString,
143
143
} = require ( 'internal/validators' ) ;
144
- const { readFileSyncUtf8 } = require ( 'internal/fs/read/utf8 ' ) ;
144
+ const syncFs = require ( 'internal/fs/sync ' ) ;
145
145
146
146
let truncateWarn = true ;
147
147
let fs ;
@@ -243,12 +243,7 @@ function access(path, mode, callback) {
243
243
* @returns {void }
244
244
*/
245
245
function accessSync ( path , mode ) {
246
- path = getValidatedPath ( path ) ;
247
- mode = getValidMode ( mode , 'access' ) ;
248
-
249
- const ctx = { path } ;
250
- binding . access ( pathModule . toNamespacedPath ( path ) , mode , undefined , ctx ) ;
251
- handleErrorFromBinding ( ctx ) ;
246
+ syncFs . access ( path , mode ) ;
252
247
}
253
248
254
249
/**
@@ -290,23 +285,7 @@ ObjectDefineProperty(exists, kCustomPromisifiedSymbol, {
290
285
* @returns {boolean }
291
286
*/
292
287
function existsSync ( path ) {
293
- try {
294
- path = getValidatedPath ( path ) ;
295
- } catch {
296
- return false ;
297
- }
298
- const ctx = { path } ;
299
- const nPath = pathModule . toNamespacedPath ( path ) ;
300
- binding . access ( nPath , F_OK , undefined , ctx ) ;
301
-
302
- // In case of an invalid symlink, `binding.access()` on win32
303
- // will **not** return an error and is therefore not enough.
304
- // Double check with `binding.stat()`.
305
- if ( isWindows && ctx . errno === undefined ) {
306
- binding . stat ( nPath , false , undefined , ctx ) ;
307
- }
308
-
309
- return ctx . errno === undefined ;
288
+ return syncFs . exists ( path ) ;
310
289
}
311
290
312
291
function readFileAfterOpen ( err , fd ) {
@@ -462,8 +441,7 @@ function readFileSync(path, options) {
462
441
463
442
// TODO(@anonrig): Do not handle file descriptor ownership for now.
464
443
if ( ! isUserFd && ( options . encoding === 'utf8' || options . encoding === 'utf-8' ) ) {
465
- path = getValidatedPath ( path ) ;
466
- return readFileSyncUtf8 ( pathModule . toNamespacedPath ( path ) , stringToFlags ( options . flag ) ) ;
444
+ return syncFs . readFileUtf8 ( path , options . flag ) ;
467
445
}
468
446
469
447
const fd = isUserFd ? path : fs . openSync ( path , options . flag , 0o666 ) ;
@@ -540,11 +518,7 @@ function close(fd, callback = defaultCloseCallback) {
540
518
* @returns {void }
541
519
*/
542
520
function closeSync ( fd ) {
543
- fd = getValidatedFd ( fd ) ;
544
-
545
- const ctx = { } ;
546
- binding . close ( fd , undefined , ctx ) ;
547
- handleErrorFromBinding ( ctx ) ;
521
+ return syncFs . close ( fd ) ;
548
522
}
549
523
550
524
/**
@@ -590,16 +564,7 @@ function open(path, flags, mode, callback) {
590
564
* @returns {number }
591
565
*/
592
566
function openSync ( path , flags , mode ) {
593
- path = getValidatedPath ( path ) ;
594
- const flagsNumber = stringToFlags ( flags ) ;
595
- mode = parseFileMode ( mode , 'mode' , 0o666 ) ;
596
-
597
- const ctx = { path } ;
598
- const result = binding . open ( pathModule . toNamespacedPath ( path ) ,
599
- flagsNumber , mode ,
600
- undefined , ctx ) ;
601
- handleErrorFromBinding ( ctx ) ;
602
- return result ;
567
+ return syncFs . open ( path , flags , mode ) ;
603
568
}
604
569
605
570
/**
@@ -1702,25 +1667,12 @@ function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) {
1702
1667
* }} [options]
1703
1668
* @returns {Stats }
1704
1669
*/
1705
- function statSync ( path , options = { bigint : false , throwIfNoEntry : true } ) {
1706
- path = getValidatedPath ( path ) ;
1707
- const ctx = { path } ;
1708
- const stats = binding . stat ( pathModule . toNamespacedPath ( path ) ,
1709
- options . bigint , undefined , ctx ) ;
1710
- if ( options . throwIfNoEntry === false && hasNoEntryError ( ctx ) ) {
1711
- return undefined ;
1712
- }
1713
- handleErrorFromBinding ( ctx ) ;
1714
- return getStatsFromBinding ( stats ) ;
1670
+ function statSync ( path , options ) {
1671
+ return syncFs . stat ( path , options ) ;
1715
1672
}
1716
1673
1717
- function statfsSync ( path , options = { bigint : false } ) {
1718
- path = getValidatedPath ( path ) ;
1719
- const ctx = { path } ;
1720
- const stats = binding . statfs ( pathModule . toNamespacedPath ( path ) ,
1721
- options . bigint , undefined , ctx ) ;
1722
- handleErrorFromBinding ( ctx ) ;
1723
- return getStatFsFromBinding ( stats ) ;
1674
+ function statfsSync ( path , options ) {
1675
+ return syncFs . statfs ( path , options ) ;
1724
1676
}
1725
1677
1726
1678
/**
@@ -2999,16 +2951,7 @@ function copyFile(src, dest, mode, callback) {
2999
2951
* @returns {void }
3000
2952
*/
3001
2953
function copyFileSync ( src , dest , mode ) {
3002
- src = getValidatedPath ( src , 'src' ) ;
3003
- dest = getValidatedPath ( dest , 'dest' ) ;
3004
-
3005
- const ctx = { path : src , dest } ; // non-prefixed
3006
-
3007
- src = pathModule . _makeLong ( src ) ;
3008
- dest = pathModule . _makeLong ( dest ) ;
3009
- mode = getValidMode ( mode , 'copyFile' ) ;
3010
- binding . copyFile ( src , dest , mode , undefined , ctx ) ;
3011
- handleErrorFromBinding ( ctx ) ;
2954
+ syncFs . copyFile ( src , dest , mode ) ;
3012
2955
}
3013
2956
3014
2957
/**
0 commit comments