Skip to content

Commit

Permalink
win: fix fs.realpath.native for long paths
Browse files Browse the repository at this point in the history
Unlike other fs.js functions that work with paths, realpath.native 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: nodejs/node#39721
PR-URL: nodejs/node#44536
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
  • Loading branch information
StefanStojanovic authored and guangwong committed Jan 3, 2023
1 parent 2a33898 commit 7015fd4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,7 @@ realpathSync.native = (path, options) => {
options = getOptions(options);
path = getValidatedPath(path);
const ctx = { path };
const result = binding.realpath(path, options.encoding, undefined, ctx);
const result = binding.realpath(pathModule.toNamespacedPath(path), options.encoding, undefined, ctx);
handleErrorFromBinding(ctx);
return result;
};
Expand Down Expand Up @@ -2758,7 +2758,7 @@ realpath.native = (path, options, callback) => {
path = getValidatedPath(path);
const req = new FSReqCallback();
req.oncomplete = callback;
return binding.realpath(path, options.encoding, req);
return binding.realpath(pathModule.toNamespacedPath(path), options.encoding, req);
};

/**
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-fs-long-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ console.log({

fs.writeFile(fullPath, 'ok', common.mustSucceed(() => {
fs.stat(fullPath, common.mustSucceed());

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

0 comments on commit 7015fd4

Please sign in to comment.