@@ -141,7 +141,6 @@ const { |
141 | 141 | validateObject, |
142 | 142 | validateString, |
143 | 143 | } = require('internal/validators'); |
144 | | -const syncFs = require('internal/fs/sync'); |
145 | 144 |
|
146 | 145 | let truncateWarn = true; |
147 | 146 | let fs; |
@@ -243,7 +242,10 @@ function access(path, mode, callback) { |
243 | 242 | * @returns {void} |
244 | 243 | */ |
245 | 244 | function accessSync(path, mode) { |
246 | | - syncFs.access(path, mode); |
| 245 | + path = getValidatedPath(path); |
| 246 | + mode = getValidMode(mode, 'access'); |
| 247 | + |
| 248 | + binding.access(pathModule.toNamespacedPath(path), mode); |
247 | 249 | } |
248 | 250 |
|
249 | 251 | /** |
@@ -285,7 +287,13 @@ ObjectDefineProperty(exists, kCustomPromisifiedSymbol, { |
285 | 287 | * @returns {boolean} |
286 | 288 | */ |
287 | 289 | function existsSync(path) { |
288 | | - return syncFs.exists(path); |
| 290 | + try { |
| 291 | + path = getValidatedPath(path); |
| 292 | + } catch { |
| 293 | + return false; |
| 294 | + } |
| 295 | + |
| 296 | + return binding.existsSync(pathModule.toNamespacedPath(path)); |
289 | 297 | } |
290 | 298 |
|
291 | 299 | function readFileAfterOpen(err, fd) { |
@@ -438,7 +446,10 @@ function readFileSync(path, options) { |
438 | 446 | options = getOptions(options, { flag: 'r' }); |
439 | 447 |
|
440 | 448 | if (options.encoding === 'utf8' || options.encoding === 'utf-8') { |
441 | | - return syncFs.readFileUtf8(path, options.flag); |
| 449 | + if (!isInt32(path)) { |
| 450 | + path = pathModule.toNamespacedPath(getValidatedPath(path)); |
| 451 | + } |
| 452 | + return binding.readFileUtf8(path, stringToFlags(options.flag)); |
442 | 453 | } |
443 | 454 |
|
444 | 455 | const isUserFd = isFd(path); // File descriptor ownership |
@@ -516,7 +527,9 @@ function close(fd, callback = defaultCloseCallback) { |
516 | 527 | * @returns {void} |
517 | 528 | */ |
518 | 529 | function closeSync(fd) { |
519 | | - return syncFs.close(fd); |
| 530 | + fd = getValidatedFd(fd); |
| 531 | + |
| 532 | + return binding.close(fd); |
520 | 533 | } |
521 | 534 |
|
522 | 535 | /** |
@@ -562,7 +575,13 @@ function open(path, flags, mode, callback) { |
562 | 575 | * @returns {number} |
563 | 576 | */ |
564 | 577 | function openSync(path, flags, mode) { |
565 | | - return syncFs.open(path, flags, mode); |
| 578 | + path = getValidatedPath(path); |
| 579 | + |
| 580 | + return binding.open( |
| 581 | + pathModule.toNamespacedPath(path), |
| 582 | + stringToFlags(flags), |
| 583 | + parseFileMode(mode, 'mode', 0o666), |
| 584 | + ); |
566 | 585 | } |
567 | 586 |
|
568 | 587 | /** |
@@ -1665,12 +1684,24 @@ function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) { |
1665 | 1684 | * }} [options] |
1666 | 1685 | * @returns {Stats} |
1667 | 1686 | */ |
1668 | | -function statSync(path, options) { |
1669 | | - return syncFs.stat(path, options); |
| 1687 | +function statSync(path, options = { bigint: false, throwIfNoEntry: true }) { |
| 1688 | + path = getValidatedPath(path); |
| 1689 | + const stats = binding.stat( |
| 1690 | + pathModule.toNamespacedPath(path), |
| 1691 | + options.bigint, |
| 1692 | + undefined, |
| 1693 | + options.throwIfNoEntry, |
| 1694 | + ); |
| 1695 | + if (stats === undefined) { |
| 1696 | + return undefined; |
| 1697 | + } |
| 1698 | + return getStatsFromBinding(stats); |
1670 | 1699 | } |
1671 | 1700 |
|
1672 | | -function statfsSync(path, options) { |
1673 | | - return syncFs.statfs(path, options); |
| 1701 | +function statfsSync(path, options = { bigint: false }) { |
| 1702 | + path = getValidatedPath(path); |
| 1703 | + const stats = binding.statfs(pathModule.toNamespacedPath(path), options.bigint); |
| 1704 | + return getStatFsFromBinding(stats); |
1674 | 1705 | } |
1675 | 1706 |
|
1676 | 1707 | /** |
@@ -1850,7 +1881,8 @@ function unlink(path, callback) { |
1850 | 1881 | * @returns {void} |
1851 | 1882 | */ |
1852 | 1883 | function unlinkSync(path) { |
1853 | | - return syncFs.unlink(path); |
| 1884 | + path = pathModule.toNamespacedPath(getValidatedPath(path)); |
| 1885 | + return binding.unlink(path); |
1854 | 1886 | } |
1855 | 1887 |
|
1856 | 1888 | /** |
@@ -2650,8 +2682,7 @@ function realpathSync(p, options) { |
2650 | 2682 | } |
2651 | 2683 | if (linkTarget === null) { |
2652 | 2684 | const ctx = { path: base }; |
2653 | | - binding.stat(baseLong, false, undefined, ctx); |
2654 | | - handleErrorFromBinding(ctx); |
| 2685 | + binding.stat(baseLong, false, undefined, true); |
2655 | 2686 | linkTarget = binding.readlink(baseLong, undefined, undefined, ctx); |
2656 | 2687 | handleErrorFromBinding(ctx); |
2657 | 2688 | } |
@@ -2946,7 +2977,14 @@ function copyFile(src, dest, mode, callback) { |
2946 | 2977 | * @returns {void} |
2947 | 2978 | */ |
2948 | 2979 | function copyFileSync(src, dest, mode) { |
2949 | | - syncFs.copyFile(src, dest, mode); |
| 2980 | + src = getValidatedPath(src, 'src'); |
| 2981 | + dest = getValidatedPath(dest, 'dest'); |
| 2982 | + |
| 2983 | + binding.copyFile( |
| 2984 | + pathModule.toNamespacedPath(src), |
| 2985 | + pathModule.toNamespacedPath(dest), |
| 2986 | + getValidMode(mode, 'copyFile'), |
| 2987 | + ); |
2950 | 2988 | } |
2951 | 2989 |
|
2952 | 2990 | /** |
|