Skip to content

Commit 25056f5

Browse files
sapphi-redrichardlau
authored andcommitted
fs: fix fs.promises.realpath for long paths on Windows
Unlike other fs functions that work with paths, realpath isn't using pathModule.toNamespacedPath prior to calling libuv function. This is causing issues on windows. Windows long path test is also improved to cover the mentioned issue. Fixes: #51031 PR-URL: #51032 Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 42b162b commit 25056f5

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/internal/fs/promises.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ async function lutimes(path, atime, mtime) {
10101010
async function realpath(path, options) {
10111011
options = getOptions(options);
10121012
path = getValidatedPath(path);
1013-
return binding.realpath(path, options.encoding, kUsePromises);
1013+
return binding.realpath(pathModule.toNamespacedPath(path), options.encoding, kUsePromises);
10141014
}
10151015

10161016
async function mkdtemp(prefix, options) {

test/parallel/test-fs-long-path.js

+3
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@ fs.writeFile(fullPath, 'ok', common.mustSucceed(() => {
4646

4747
// Tests https://github.com/nodejs/node/issues/39721
4848
fs.realpath.native(fullPath, common.mustSucceed());
49+
50+
// Tests https://github.com/nodejs/node/issues/51031
51+
fs.promises.realpath(fullPath).then(common.mustCall(), common.mustNotCall());
4952
}));

0 commit comments

Comments
 (0)