Skip to content

Commit

Permalink
fs: fix readdir recursive sync & callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Arrowood committed Jul 7, 2023
1 parent 38dee8a commit 411ca77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1437,14 +1437,16 @@ function readdirSyncRecursive(basePath, options) {
);
handleErrorFromBinding(ctx);

for (let i = 0; i < readdirResult.length; i++) {
if (withFileTypes) {
if (withFileTypes) {
for (let i = 0; i < readdirResult[0].length; i++) {
const dirent = getDirent(path, readdirResult[0][i], readdirResult[1][i]);
ArrayPrototypePush(readdirResults, dirent);
if (dirent.isDirectory()) {
ArrayPrototypePush(pathsQueue, pathModule.join(dirent.path, dirent.name));
}
} else {
}
} else {
for (let i = 0; i < readdirResult.length; i++) {
const resultPath = pathModule.join(path, readdirResult[i]);
const relativeResultPath = pathModule.relative(basePath, resultPath);
const stat = binding.internalModuleStat(resultPath);
Expand Down
1 change: 1 addition & 0 deletions test/sequential/test-fs-readdir-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function getDirentPath(dirent) {
}

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

0 comments on commit 411ca77

Please sign in to comment.