admin管理员组

文章数量:1336084

readdir() spec says:

If a file is removed from or added to the directory after the most recent call to opendir() or rewinddir(), whether a subsequent call to readdir() returns an entry for that file is unspecified.

Does this imply that as long as the entry has existed since before opendir() call and isn't concurrently deleted, it will be returned?

I'm concerned that concurrent addition/deletion of other entries can reshuffle the whatever data structure backs the set of directory entries and move the entries not yet visited behind my iterator or those already visited ahead of it. I assume this can happen since the order is not guaranteed to remain consistent between opendir() calls.

readdir() spec says:

If a file is removed from or added to the directory after the most recent call to opendir() or rewinddir(), whether a subsequent call to readdir() returns an entry for that file is unspecified.

Does this imply that as long as the entry has existed since before opendir() call and isn't concurrently deleted, it will be returned?

I'm concerned that concurrent addition/deletion of other entries can reshuffle the whatever data structure backs the set of directory entries and move the entries not yet visited behind my iterator or those already visited ahead of it. I assume this can happen since the order is not guaranteed to remain consistent between opendir() calls.

Share Improve this question asked Nov 21, 2024 at 1:00 yuri kilochekyuri kilochek 13.6k2 gold badges33 silver badges63 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Yes, that's what it implies. Adding/removing files should not affect whether you can list the other files in the directory. The implementation must ensure that these entries are not skipped or repeated due to other changes to the directory.

It's not like the problem you often run into when programming with a language that provides an array traversal operator (e.g. for element in list: in Python), where they get out of sync if there's an insertion or deletion in the array.

本文标签: