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.
1 Answer
Reset to default 2Yes, 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.
本文标签:
版权声明:本文标题:linux - Can posix readdir() skip or repeat entries when another process concurrently modifies the directory? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742320035a2452599.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论