Skip to content

Commit

Permalink
fs,win: fix readdir for named pipe
Browse files Browse the repository at this point in the history
PR-URL: #56110
Fixes: #56002
Refs: #55623
Refs: #56088
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
huseyinacacak-janea authored Dec 10, 2024
1 parent eef06f7 commit f184a0a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1986,8 +1986,29 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {

BufferValue path(isolate, args[0]);
CHECK_NOT_NULL(*path);
#ifdef _WIN32
// On Windows, some API functions accept paths with trailing slashes,
// while others do not. This code checks if the input path ends with
// a slash (either '/' or '\\') and, if so, ensures that the processed
// path also ends with a trailing backslash ('\\').
bool slashCheck = false;
if (path.ToStringView().ends_with("/") ||
path.ToStringView().ends_with("\\")) {
slashCheck = true;
}
#endif

ToNamespacedPath(env, &path);

#ifdef _WIN32
if (slashCheck) {
size_t new_length = path.length() + 1;
path.AllocateSufficientStorage(new_length + 1);
path.SetLengthAndZeroTerminate(new_length);
path.out()[new_length - 1] = '\\';
}
#endif

const enum encoding encoding = ParseEncoding(isolate, args[1], UTF8);

bool with_types = args[2]->IsTrue();
Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-fs-readdir-pipe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const { readdir, readdirSync } = require('fs');

if (!common.isWindows) {
common.skip('This test is specific to Windows to test enumerate pipes');
}

// Ref: https://github.com/nodejs/node/issues/56002
// This test is specific to Windows.

const pipe = '\\\\.\\pipe\\';

const { length } = readdirSync(pipe);
assert.ok(length >= 0, `${length} is not greater or equal to 0`);

readdir(pipe, common.mustSucceed((files) => {
assert.ok(files.length >= 0, `${files.length} is not greater or equal to 0`);
}));

0 comments on commit f184a0a

Please sign in to comment.