From ef26b9b0fea9c1b27cc31f33b9b74642de944315 Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Tue, 13 Sep 2022 13:48:53 +0200 Subject: [PATCH] win: fix fs.realpath.native for long paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/issues/39721 PR-URL: https://github.com/nodejs/node/pull/44536 Reviewed-By: Luigi Pinca Reviewed-By: Gerhard Stöbich --- lib/fs.js | 4 ++-- test/parallel/test-fs-long-path.js | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 352e4293ca4ea8..e2fcb084ee575a 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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; }; @@ -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); }; /** diff --git a/test/parallel/test-fs-long-path.js b/test/parallel/test-fs-long-path.js index 1cb66fa6046152..3f808496ae53f2 100644 --- a/test/parallel/test-fs-long-path.js +++ b/test/parallel/test-fs-long-path.js @@ -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()); }));