Skip to content

Commit 411ca77

Browse files
author
Ethan Arrowood
committed
fs: fix readdir recursive sync & callback
Refs: #48640
1 parent 38dee8a commit 411ca77

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

lib/fs.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,14 +1437,16 @@ function readdirSyncRecursive(basePath, options) {
14371437
);
14381438
handleErrorFromBinding(ctx);
14391439

1440-
for (let i = 0; i < readdirResult.length; i++) {
1441-
if (withFileTypes) {
1440+
if (withFileTypes) {
1441+
for (let i = 0; i < readdirResult[0].length; i++) {
14421442
const dirent = getDirent(path, readdirResult[0][i], readdirResult[1][i]);
14431443
ArrayPrototypePush(readdirResults, dirent);
14441444
if (dirent.isDirectory()) {
14451445
ArrayPrototypePush(pathsQueue, pathModule.join(dirent.path, dirent.name));
14461446
}
1447-
} else {
1447+
}
1448+
} else {
1449+
for (let i = 0; i < readdirResult.length; i++) {
14481450
const resultPath = pathModule.join(path, readdirResult[i]);
14491451
const relativeResultPath = pathModule.relative(basePath, resultPath);
14501452
const stat = binding.internalModuleStat(resultPath);

test/sequential/test-fs-readdir-recursive.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ function getDirentPath(dirent) {
131131
}
132132

133133
function assertDirents(dirents) {
134+
assert.strictEqual(dirents.length, expected.length);
134135
dirents.sort((a, b) => (getDirentPath(a) < getDirentPath(b) ? -1 : 1));
135136
for (const [i, dirent] of dirents.entries()) {
136137
assert(dirent instanceof fs.Dirent);

0 commit comments

Comments
 (0)