是否有任何 POSIX 函数或 glibc 扩展实现广度优先的文件树遍历?

发布于 2024-08-10 07:22:10 字数 384 浏览 3 评论 0原文

我正在编写一个守护进程,它利用 inotify 来监视文件访问,并且在递归搜索中不要错过任何内容,这一点至关重要。我发现了这个有趣的想法并开始实施它。

ftw() 和 ftw64() 不使用广度优先算法,它更“前序”。 nftw() 为我提供了深度优先的选项,但我担心上部叶子中的竞争。

我希望我遗漏了一些东西,也许是 GNU 扩展?或者我只是想用类型安全的回调来实现我自己的(我真的不想这样做)?

或者,对于此类应用程序,我对广度优先相对于深度优先的优势的理解是否错误?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新一帅帅 2024-08-17 07:22:10

查看“nftw()”的规范,FTW_DEPTH 标志进行后序(深度优先)遍历,在访问目录节点之前访问子目录。

我认为任何标准算法都不会进行广度优先搜索。

想必,您应该基于 nftw() 接口编写一个 bfftw() 。请注意,在进行扫描时,您必须对要递归访问的项目(目录)进行排队。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文