Skip to content

Commit

Permalink
fs: fix fs.promises.realpath for long paths on Windows
Browse files Browse the repository at this point in the history
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 <livia@cirno.name>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
sapphi-red authored and richardlau committed Mar 25, 2024
1 parent 9474ff4 commit f823041
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/fs/promises.js
Expand Up @@ -1010,7 +1010,7 @@ async function lutimes(path, atime, mtime) {
async function realpath(path, options) {
options = getOptions(options);
path = getValidatedPath(path);
return binding.realpath(path, options.encoding, kUsePromises);
return binding.realpath(pathModule.toNamespacedPath(path), options.encoding, kUsePromises);
}

async function mkdtemp(prefix, options) {
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-fs-long-path.js
Expand Up @@ -46,4 +46,7 @@ fs.writeFile(fullPath, 'ok', common.mustSucceed(() => {

// Tests https://github.com/nodejs/node/issues/39721
fs.realpath.native(fullPath, common.mustSucceed());

// Tests https://github.com/nodejs/node/issues/51031
fs.promises.realpath(fullPath).then(common.mustCall(), common.mustNotCall());
}));

0 comments on commit f823041

Please sign in to comment.