Repository navigation
fs#readdir(Sync) breaks when recursive + withFileTypes combined #48858
Copy link
Copy link
Closed
Labels
fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.
Description
Activity
I just ran into this on Node v20.5.0.
Reacted by Evgeniy Talagaev and Jason MitchellThis is also an issue with the callback
fs.readdiras noted in the original issueReacted by Matt Cowley- addedfsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.
on Jul 26, 2023 - changed the title
[-]fs#readdirSync breaks when recursive + withFileTypes combined[/-][+]fs#readdir(Sync) breaks when recursive + withFileTypes combined[/+]on Jul 26, 2023 - linked a pull request that will close this issuefs: fix readdir recursive sync & callback #48698
on Aug 10, 2023 - added a commit that references this issue
on Aug 12, 2023 This is great news! Where can I find information about when we can expect v20.5.2 to be published (assuming this fix will be in that release)?
- added a commit that references this issue
on Aug 14, 2023 - added 2 commits that reference this issue
on Aug 15, 2023 - added 2 commits that reference this issue
on Aug 16, 2023 workaround:
const fs = require('fs'); const path = './public/' fs.readdirSync(path, { recursive: true, withFileTypes: false }) .forEach( (file) => { // check if file is directory, if not then log the path/file if (!fs.lstatSync(path+file).isDirectory()) { console.log(file); }; }, );
Reacted by Tung Nguyen and Chris Sophos- added a commit that references this issue
on Oct 28, 2023 - added 2 commits that reference this issue
on Apr 25, 2024 I still have this issue with 22.14.0. Is there something I'm doing wrong, or is there a specific version I can expect it to work?
Metadata
Metadata
Assignees
Labels
fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.
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?
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/readdirSyncfail to report all files in the current directory when therecursiveoption is supplied at the same time as thewithFileTypesoption.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