最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论