Skip to content

win: fix fs.realpath.native for long paths

On windows when using fs.realpath.native, fs.realpathSync.native and fs.promises.realpath on long path, ENOENT is thrown. On the other hand, long paths work well with fs.realpath and fs.realpathSync. On Linux, all of the mentioned realpath versions work as expected.

The problem is that windows API functions do not work with paths longer then 260 characters by default. There is a way to enable long path support via application manifest file, but it only works starting from Windows 10 version 1607 and it relies on registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled being set. Since that is not necessarily always the case with machines running node, this approach wouldn't work. The other way to enable working with long paths is to add a \\?\ prefix to the path prior to using it in windows API functions. This approach is used by all fs functions working with paths, with the exception of fs.realpath.native and fs.realpathSync.native.

Fix is made in fs.js implementation of fs.realpath.native, fs.realpathSync.native, so their path preprocessing matches to the other functions.

An existing windows long path test is improved to cover the issue that is fixed by these changes.

Fixes: https://github.com/nodejs/node/issues/39721

Merge request reports

Loading