Closed hainesr closed 4 months ago
Thank you for the report. From that behavior it looks like Dir#each automatically rewinds just before returning. It should be trivial to fix, we just need to verify that is indeed what the implementation does in CRuby.
Actually it's the opposite, Dir#each rewinds before starting to iterate: https://github.com/ruby/ruby/blob/dddf62426b7a384715dd558773723ecbdfa37a11/dir.c#L844-L859
Fixed in db4908a963b6b41ad8a4901da89b76bce1cbcf32.
When using
Dir
to create and list items in a directory I think I've spotted different behaviour in truffleruby compared to ruby and jruby.TL;DR: if I create a directory, and some items in it, then immediately try to loop through the new directory's contents, the new items are not traversed until the directory is rewound. In ruby and jruby they are traversed immediately.
To replicate I used this script:
With ruby:
With jruby:
With truffleruby:
In the truffleruby case you can see that nothing is listed second time, almost as if it's remembering where it ended up after listing the empty directory, but not having "seen" the new entries yet either. In the other rubies you can keep looping through the directory entries without
rewind
ing in between.