node icon indicating copy to clipboard operation
node copied to clipboard

fs,win: fix readdir for named pipe

Open huseyinacacak-janea opened this issue 2 months ago • 5 comments

This PR fixes the issue by giving the user the responsibility to add/remove trailing slashes for fs.readdir. Examples:

> require('fs').readdirSync('\\\\.\\pipe').length
Uncaught Error: ENOTDIR: not a directory, scandir '\\.\pipe'
    at Object.readdirSync (node:fs:1503:26) {
  errno: -4052,
  code: 'ENOTDIR',
  syscall: 'scandir',
  path: '\\\\.\\pipe'
}
> require('fs').readdirSync('\\\\.\\pipe\\').length
243

For additional context, most of the paths are resolved in resolve() in Node.js. This relies on normalizeString() which removes the trailing slashes. Since resolve() is widely used, any change in this function can cause many breaks as seen here.

Additionally, fs.readdir() internally relies on NtQueryDirectoryFile. This API doesn't allow us to use pipe paths without trailing slashes. On the other hand, fs.openSync() uses a different underlying API and works without trailing slashes in the physical drive paths. This difference highlights some inconsistencies across API functions, which seem to stem from the combined behaviors of libuv and the Windows API.

I'm open to suggestions.

cc: @Flarna

Fixes: https://github.com/nodejs/node/issues/56002 Refs: https://github.com/nodejs/node/pull/55623 Refs: https://github.com/nodejs/node/pull/56088

huseyinacacak-janea avatar Dec 02 '24 13:12 huseyinacacak-janea