Skip to content

Commit 595851b

Browse files
huseyinacacak-janeaaduh95
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 f10239f commit 595851b

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/node_file.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,8 +1986,29 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
19861986

19871987
BufferValue path(isolate, args[0]);
19881988
CHECK_NOT_NULL(*path);
1989+
#ifdef _WIN32
1990+
// On Windows, some API functions accept paths with trailing slashes,
1991+
// while others do not. This code checks if the input path ends with
1992+
// a slash (either '/' or '\\') and, if so, ensures that the processed
1993+
// path also ends with a trailing backslash ('\\').
1994+
bool slashCheck = false;
1995+
if (path.ToStringView().ends_with("/") ||
1996+
path.ToStringView().ends_with("\\")) {
1997+
slashCheck = true;
1998+
}
1999+
#endif
2000+
19892001
ToNamespacedPath(env, &path);
19902002

2003+
#ifdef _WIN32
2004+
if (slashCheck) {
2005+
size_t new_length = path.length() + 1;
2006+
path.AllocateSufficientStorage(new_length + 1);
2007+
path.SetLengthAndZeroTerminate(new_length);
2008+
path.out()[new_length - 1] = '\\';
2009+
}
2010+
#endif
2011+
19912012
const enum encoding encoding = ParseEncoding(isolate, args[1], UTF8);
19922013

19932014
bool with_types = args[2]->IsTrue();

test/parallel/test-fs-readdir-pipe.js

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy