Closed
Description
Version
18.17.0
Platform
Darwin [snip] 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64
Subsystem
No response
What steps will reproduce the bug?
touch a b c d e f
ls
a b c d e f
node
Welcome to Node.js v18.17.0.
Type ".help" for more information.
> const { readdir, readdirSync } = require('fs');
undefined
> readdir('./', console.log);
undefined
> null [ 'a', 'b', 'c', 'd', 'e', 'f' ]
> readdir('./', { withFileTypes: true }, console.log);
undefined
> null [
Dirent { name: 'a', path: './', [Symbol(type)]: 1 },
Dirent { name: 'b', path: './', [Symbol(type)]: 1 },
Dirent { name: 'c', path: './', [Symbol(type)]: 1 },
Dirent { name: 'd', path: './', [Symbol(type)]: 1 },
Dirent { name: 'e', path: './', [Symbol(type)]: 1 },
Dirent { name: 'f', path: './', [Symbol(type)]: 1 }
]
> readdir('./', { recursive: true }, console.log);
null [ 'a', 'b', 'c', 'd', 'e', 'f' ]
undefined
>
> readdir('./', { recursive: true, withFileTypes: true }, console.log);
null [
Dirent { name: 'a', path: './', [Symbol(type)]: 1 },
Dirent { name: 'b', path: './', [Symbol(type)]: 1 }
]
undefined
>
> readdirSync('./', { recursive: true });
[ 'a', 'b', 'c', 'd', 'e', 'f' ]
> readdirSync('./', { withFileTypes: true });
[
Dirent { name: 'a', path: './', [Symbol(type)]: 1 },
Dirent { name: 'b', path: './', [Symbol(type)]: 1 },
Dirent { name: 'c', path: './', [Symbol(type)]: 1 },
Dirent { name: 'd', path: './', [Symbol(type)]: 1 },
Dirent { name: 'e', path: './', [Symbol(type)]: 1 },
Dirent { name: 'f', path: './', [Symbol(type)]: 1 }
]
> readdirSync('./', { recursive: true, withFileTypes: true });
[
Dirent { name: 'a', path: './', [Symbol(type)]: 1 },
Dirent { name: 'b', path: './', [Symbol(type)]: 1 }
]
>
How often does it reproduce? Is there a required condition?
Seemingly always
What is the expected behavior? Why is that the expected behavior?
Should return all the files
What do you see instead?
See the above reproduction. Even with no nested subdirectories, readdir
/ readdirSync
fail to report all files in the current directory when the recursive
option is supplied at the same time as the withFileTypes
option.
Additional information
It looks like #48640 discusses this in the comments, and #48698 fixes this, but I did not see an actual issue tracking this broken behavior itself, and that it was shipped in 18.17.0