Skip to content

Commit 8b50160

Browse files
win: fix fs.realpath.native for long paths
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: #39721 PR-URL: #44536 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
1 parent 050a145 commit 8b50160

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/fs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ realpathSync.native = (path, options) => {
26002600
options = getOptions(options);
26012601
path = getValidatedPath(path);
26022602
const ctx = { path };
2603-
const result = binding.realpath(path, options.encoding, undefined, ctx);
2603+
const result = binding.realpath(pathModule.toNamespacedPath(path), options.encoding, undefined, ctx);
26042604
handleErrorFromBinding(ctx);
26052605
return result;
26062606
};
@@ -2760,7 +2760,7 @@ realpath.native = (path, options, callback) => {
27602760
path = getValidatedPath(path);
27612761
const req = new FSReqCallback();
27622762
req.oncomplete = callback;
2763-
return binding.realpath(path, options.encoding, req);
2763+
return binding.realpath(pathModule.toNamespacedPath(path), options.encoding, req);
27642764
};
27652765

27662766
/**

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

+3
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ console.log({
4343

4444
fs.writeFile(fullPath, 'ok', common.mustSucceed(() => {
4545
fs.stat(fullPath, common.mustSucceed());
46+
47+
// Tests https://github.com/nodejs/node/issues/39721
48+
fs.realpath.native(fullPath, common.mustSucceed());
4649
}));

0 commit comments

Comments
 (0)