Leaf directories (Re: Why is find so slow)
Larry Wall
lwall at jpl-devvax.JPL.NASA.GOV
Sun Oct 14 07:07:53 AEST 1990
In article <26981 at mimsy.umd.edu> chris at mimsy.umd.edu (Chris Torek) writes:
: In article <F&0u96p2 at cs.psu.edu> flee at guardian.cs.psu.edu (Felix Lee) writes:
: >Leaf directories are directories with no subdirectories. A leaf
: >directory has a link count <= 2.
:
: It is easier than that (and harder than this, which leaves out error
: checking):
:
: d = opendir(dir);
: fstat(dirfd(d), &st);
: nsubdirs = st.st_nlink - 2;
: while ((dp = readdir(d)) != NULL) {
: if (need_stat_anyway || nsubdirs > 0) {
: get_stat(dir, dp->d_name, &st);
: if (S_ISDIR(st.st_mode))
: nsubdirs--;
: }
: ...
: }
If find is done this way, it would behoove us to sort subdirectories
before filenames in each directory so that nsubdirs goes to 0 as soon
as possible.
Larry Wall
lwall at jpl-devvax.jpl.nasa.gov
More information about the Comp.unix.shell
mailing list