Skip to content

Commit

Permalink
mend
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Arrowood committed Jul 19, 2023
1 parent 411ca77 commit 7bcf27f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,12 @@ function readdirSyncRecursive(basePath, options) {
handleErrorFromBinding(ctx);

if (withFileTypes) {
for (let i = 0; i < readdirResult[0].length; i++) {
// Calling `readdir` with `withFileTypes=true`, the result is an array of arrays.
// The first array is the names, and the second array is the types.
// They are guaranteed to be the same length; hence, setting `length` to the length
// of the first array within the result.
const length = readdirResult[0].length;
for (let i = 0; i < length; i++) {
const dirent = getDirent(path, readdirResult[0][i], readdirResult[1][i]);
ArrayPrototypePush(readdirResults, dirent);
if (dirent.isDirectory()) {
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 @@ -135,6 +135,7 @@ function assertDirents(dirents) {
dirents.sort((a, b) => (getDirentPath(a) < getDirentPath(b) ? -1 : 1));
for (const [i, dirent] of dirents.entries()) {
assert(dirent instanceof fs.Dirent);
assert.notStrictEqual(dirent.name, undefined);
assert.strictEqual(getDirentPath(dirent), expected[i]);
}
}
Expand Down

0 comments on commit 7bcf27f

Please sign in to comment.