doc: clarify how fs.Dirent file types are determined#64532
Open
soreavis wants to merge 1 commit into
Open
Conversation
The file type of a directory entry returned by fs.readdir() or fs.opendir() is the type reported by the operating system's directory listing. Node.js falls back to lstat() only when the reported type is unknown, and some file systems may report a type that differs from what lstat() would return. Document this in the fs.Dirent class introduction, with fs.lstat() as the accurate alternative. Fixes: nodejs#30646 Signed-off-by: Julian Soreavis <julian.soreavis@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
fs.Direntdocs don't say where entry file types come from — the confusion in #30646, where the type reported on a remotely mounted file system didn't matchlstat()and @addaleax suggested documenting that "the type of the entry may be dependent on the file system and operating system". This adds one paragraph to thefs.Direntclass intro: the type of an entry from a directory read is the type reported by the operating system, it may depend on the file system,lstat()is only used as a fallback when the reported type is unknown, andfs.lstat()is the accurate alternative.Verified against
lib/internal/fs/utils.js(getDirent/getDirentsfall back tolstatonly onUV_DIRENT_UNKNOWN) andsrc/node_file.cc(the type comes fromuv_fs_scandir_next, no stat call). The wording is scoped to directory reads (fs.readdir(),fs.opendir()) becausefs.glob()withwithFileTypesbuilds its dirents fromlstat()directly.I used an AI assistant while researching and drafting this change; I've verified the behavior and the wording against the source myself and take full responsibility for it.
Fixes: #30646