@@ -141,7 +141,7 @@ const {
141141 validateObject,
142142 validateString,
143143} = require ( 'internal/validators' ) ;
144- const { readFileSyncUtf8 } = require ( 'internal/fs/read/utf8 ' ) ;
144+ const syncFs = require ( 'internal/fs/sync ' ) ;
145145
146146let truncateWarn = true ;
147147let fs ;
@@ -243,12 +243,7 @@ function access(path, mode, callback) {
243243 * @returns {void }
244244 */
245245function 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 ) ;
252247}
253248
254249/**
@@ -290,23 +285,7 @@ ObjectDefineProperty(exists, kCustomPromisifiedSymbol, {
290285 * @returns {boolean }
291286 */
292287function 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 ) ;
310289}
311290
312291function readFileAfterOpen ( err , fd ) {
@@ -462,8 +441,7 @@ function readFileSync(path, options) {
462441
463442 // TODO(@anonrig): Do not handle file descriptor ownership for now.
464443 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 ) ;
467445 }
468446
469447 const fd = isUserFd ? path : fs . openSync ( path , options . flag , 0o666 ) ;
@@ -540,11 +518,7 @@ function close(fd, callback = defaultCloseCallback) {
540518 * @returns {void }
541519 */
542520function closeSync ( fd ) {
543- fd = getValidatedFd ( fd ) ;
544-
545- const ctx = { } ;
546- binding . close ( fd , undefined , ctx ) ;
547- handleErrorFromBinding ( ctx ) ;
521+ return syncFs . close ( fd ) ;
548522}
549523
550524/**
@@ -590,16 +564,7 @@ function open(path, flags, mode, callback) {
590564 * @returns {number }
591565 */
592566function 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 ) ;
603568}
604569
605570/**
@@ -1702,25 +1667,12 @@ function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) {
17021667 * }} [options]
17031668 * @returns {Stats }
17041669 */
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 ) ;
17151672}
17161673
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 ) ;
17241676}
17251677
17261678/**
@@ -2999,16 +2951,7 @@ function copyFile(src, dest, mode, callback) {
29992951 * @returns {void }
30002952 */
30012953function 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 ) ;
30122955}
30132956
30142957/**
0 commit comments