Skip to content

Commit

Permalink
fs,win: fix readdir for named pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
huseyinacacak-janea committed Dec 2, 2024
1 parent 853b304 commit 54534dd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1986,8 +1986,26 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {

BufferValue path(isolate, args[0]);
CHECK_NOT_NULL(*path);
#ifdef _WIN32
bool slashCheck = false;
if (path.ToStringView().ends_with("/") ||
path.ToStringView().ends_with("\\")) {
slashCheck = true;
}
#endif

ToNamespacedPath(env, &path);

#ifdef _WIN32
if (slashCheck) {
std::string result = path.ToString() + "\\";
size_t new_length = result.size();
path.AllocateSufficientStorage(new_length + 1);
path.SetLength(new_length);
memcpy(path.out(), result.c_str(), result.size() + 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\\';

assert.ok(readdirSync(pipe).length >= 0);

readdir(pipe, common.mustCall((err, files) => {
assert.ok(err == null);
assert.ok(files.length >= 0);
}));

0 comments on commit 54534dd

Please sign in to comment.