From 030aebb4dd4d306e976bad63a274b9896dcc8451 Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Tue, 6 Sep 2022 14:17:07 +0200 Subject: [PATCH] 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: https://github.com/nodejs/node/issues/39721 --- 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 ffa216f35388e0..c618bd2cac89cc 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -2612,7 +2612,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; }; @@ -2772,7 +2772,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()); }));