Do any POSIX functions or glibc extensions implement a breadth-first file tree walk?

只谈情不闲聊 提交于 2019-12-22 10:49:36

问题


I am writing a daemon that utilizes inotify to monitor file access and it is critical that I don't miss anything on a recursive search. I found this interesting idea and have begun to implement it.

ftw() and ftw64() do not use a breadth-first algorithm, its more "pre-order". nftw() gives me the option of depth-first, but I'm worried about races in upper leaves.

I'm hoping that I'm missing something, perhaps a GNU extension? Or am I just looking at implementing my own with type safe call backs (something I'd really rather not do) ?

Or, is my understanding of the advantages of breadth-first over depth-first erroneous for this type of application?


回答1:


Looking at the spec for 'nftw()', the FTW_DEPTH flag does a post-order (depth first) traversal, visiting the sub-directories before visiting the directory node.

I don't think any of the standard algorithms do a breadth-first search.

Presumably, you should write a bfftw() based on the nftw() interface. Note that you have to queue the items to be visited recursively (directories) while doing the scan.



来源:https://stackoverflow.com/questions/1647572/do-any-posix-functions-or-glibc-extensions-implement-a-breadth-first-file-tree-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!