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 RafaelGSS committed Jan 2, 2024
1 parent 652af45 commit 091098f
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 @@ -1160,7 +1160,7 @@ async function realpath(path, options) {
options = getOptions(options);
path = getValidatedPath(path);
return await PromisePrototypeThen(
binding.realpath(path, options.encoding, kUsePromises),
binding.realpath(pathModule.toNamespacedPath(path), options.encoding, kUsePromises),
undefined,
handleErrorFromBinding,
);
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 091098f

Please sign in to comment.