本文介绍了做任何POSIX函数或glibc的扩展,实现广度优先的文件树走?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写利用的inotify监视文件访问权限的守护进程,这是至关重要的,我不会错过的递归搜索任何东西。我发现这个有趣的想法并已经开始实施它

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()和ftw64()不使用广度优先算法,它更多的pre-秩序。 nftw()给我深度优先的选择,但我很担心在上部叶的比赛。

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.

我希望我失去了一些东西,也许是一个GNU扩展?或者,我只是在寻找实现自己的类型安全的回调(这是我真的不想这样做)?

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?

推荐答案

纵观规范的的,该FTW_DEPTH标志做了后序(深度优先)遍历,逛子目录访问的目录节点之前。

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,你应该写一bfftw()基于nftw()接口。需要注意的是,你要排队的项目进行递归(目录)参观,在做扫描。

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.

这篇关于做任何POSIX函数或glibc的扩展,实现广度优先的文件树走?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:22