linux - Can posix readdir() skip or repeat entries when another process concurrently modifies the directory? - Stack Overflow

readdir() spec says:If a file is removed from or added to the directory after the mostrecent call to o

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742320035a4421623.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信