Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0331b3f

Browse filesBrowse files
huseyinacacak-janearuyadorno
authored andcommitted
fs,win: fix readdir for named pipe
PR-URL: #56110 Fixes: #56002 Refs: #55623 Refs: #56088 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 598fe04 commit 0331b3f
Copy full SHA for 0331b3f

File tree

Expand file treeCollapse file tree

2 files changed

+42
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+42
-0
lines changed
Open diff view settings
Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,8 +1887,29 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
18871887

18881888
BufferValue path(isolate, args[0]);
18891889
CHECK_NOT_NULL(*path);
1890+
#ifdef _WIN32
1891+
// On Windows, some API functions accept paths with trailing slashes,
1892+
// while others do not. This code checks if the input path ends with
1893+
// a slash (either '/' or '\\') and, if so, ensures that the processed
1894+
// path also ends with a trailing backslash ('\\').
1895+
bool slashCheck = false;
1896+
if (path.ToStringView().ends_with("/") ||
1897+
path.ToStringView().ends_with("\\")) {
1898+
slashCheck = true;
1899+
}
1900+
#endif
1901+
18901902
ToNamespacedPath(env, &path);
18911903

1904+
#ifdef _WIN32
1905+
if (slashCheck) {
1906+
size_t new_length = path.length() + 1;
1907+
path.AllocateSufficientStorage(new_length + 1);
1908+
path.SetLengthAndZeroTerminate(new_length);
1909+
path.out()[new_length - 1] = '\\';
1910+
}
1911+
#endif
1912+
18921913
const enum encoding encoding = ParseEncoding(isolate, args[1], UTF8);
18931914

18941915
bool with_types = args[2]->IsTrue();
Collapse file
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const { readdir, readdirSync } = require('fs');
6+
7+
if (!common.isWindows) {
8+
common.skip('This test is specific to Windows to test enumerate pipes');
9+
}
10+
11+
// Ref: https://github.com/nodejs/node/issues/56002
12+
// This test is specific to Windows.
13+
14+
const pipe = '\\\\.\\pipe\\';
15+
16+
const { length } = readdirSync(pipe);
17+
assert.ok(length >= 0, `${length} is not greater or equal to 0`);
18+
19+
readdir(pipe, common.mustSucceed((files) => {
20+
assert.ok(files.length >= 0, `${files.length} is not greater or equal to 0`);
21+
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.