Skip to content

Commit 3435146

Browse files
StefanStojanovicjuanarbol
authored andcommitted
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 1ca69c6 commit 3435146

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
@@ -2598,7 +2598,7 @@ realpathSync.native = (path, options) => {
25982598
options = getOptions(options);
25992599
path = getValidatedPath(path);
26002600
const ctx = { path };
2601-
const result = binding.realpath(path, options.encoding, undefined, ctx);
2601+
const result = binding.realpath(pathModule.toNamespacedPath(path), options.encoding, undefined, ctx);
26022602
handleErrorFromBinding(ctx);
26032603
return result;
26042604
};
@@ -2758,7 +2758,7 @@ realpath.native = (path, options, callback) => {
27582758
path = getValidatedPath(path);
27592759
const req = new FSReqCallback();
27602760
req.oncomplete = callback;
2761-
return binding.realpath(path, options.encoding, req);
2761+
return binding.realpath(pathModule.toNamespacedPath(path), options.encoding, req);
27622762
};
27632763

27642764
/**

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)