-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
fs::read_dir() and ReadDir need clear warnings about not relying on iteration order #63183
Copy link
Copy link
Closed
Closed
Copy link
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The docs for
fs::read_dir()andfs::ReadDirneed to clearly state that iteration order is implementation defined and may vary not just between OS's but between identical versions of a directory on different filesystems.Currently the warning on
fs::read_dir()is uselessly vague:Meanwhile even this warning is completely missing from
ReadDir.Finding the semantics on ordering requires going through the docs for the target platform:
opendir()does not specify order but links toreaddir()which states:FindFirstFileAdoes not specify order but links toFindNextFilewhich states:In both cases the relevant information is two links deep which isn't really acceptable for stdlib documentation.
I want to note that I just spent 20 minutes trying to figure this out from a unit test that was dependent on this ordering and was passing locally but failing on our CI server even though both machines are running Linux x64. The problem was I'm running btrfs (which apparently returns files in lexicographical order, or just happened to return them that way) while I'm not entirely sure what filesystem the CI server is using (build jobs are running inside Docker anyway). Either way it turns out they iterated identical copies of the same directory in different orders. Frustratingly, a very similar test also depending on the ordering of
read_dir()but for a different directory was passing on both machines, which lead me to initially discount that it might have been an issue of iteration order.This issue has been assigned to @ali-raheem via this comment.