Article View: comp.unix.shell
Article #1489Re: Leaf directories (Re: Why is find so slow)
From: Chris Torek
Date: Sat, 13 Oct 1990 14:03
Date: Sat, 13 Oct 1990 14:03
28 lines
1374 bytes
1374 bytes
In article <F&0u96p2@cs.psu.edu> flee@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--;
}
...
}
(pre-POSIX programmers pwill pneed, er, will need to write
(st.st_mode & S_IFMT) == S_IFDIR
rather than S_ISDIR(st.st_mode)).
This is susceptible to error if the file system is active, but that
is no change; find has always had this problem.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain: chris@cs.umd.edu Path: uunet!mimsy!chris
Technical Details
Message-ID:
<26981@mimsy.umd.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!ames!haven!mimsy!chrisReferences:
<F&gya5o2@cs.psu.edu> <15052@hydra.gatech.EDU> <F&0u96p2@cs.psu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!ames!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.unix.shell Subject: Re: Leaf directories (Re: Why is find so slow) Message-ID: <26981@mimsy.umd.edu> Date: 13 Oct 90 14:03:32 GMT References: <F&gya5o2@cs.psu.edu> <15052@hydra.gatech.EDU> <F&0u96p2@cs.psu.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 28