From 9d6a279437fb59e4d7c786da8bf285ef5cbf9ac1 Mon Sep 17 00:00:00 2001 From: jay Date: Wed, 27 Jul 2005 10:25:24 +0000 Subject: [PATCH] If the link count od a directory starts off less than two, disable the leaf optimisation for this directory. --- find/find.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/find/find.c b/find/find.c index 7a02c23..0da0e9d 100644 --- a/find/find.c +++ b/find/find.c @@ -1,5 +1,6 @@ /* find -- search for files in a directory hierarchy - Copyright (C) 1990, 91, 92, 93, 94, 2000, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1990, 91, 92, 93, 94, 2000, + 2003, 2004, 2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,7 +22,9 @@ Jay Plett , and Tim Wood . The idea for -print0 and xargs -0 came from - Dan Bernstein . */ + Dan Bernstein . + Improvements have been made by James Youngman . +*/ #include "defs.h" @@ -1799,12 +1802,22 @@ static void process_dir (char *pathname, char *name, int pathlen, struct stat *statp, char *parent) { int subdirs_left; /* Number of unexamined subdirs in PATHNAME. */ + boolean subdirs_unreliable; /* if true, cannot use dir link count as subdir limif (if false, it may STILL be unreliable) */ int idx; /* Which entry are we on? */ struct stat stat_buf; struct savedir_dirinfo *dirinfo; - subdirs_left = statp->st_nlink - 2; /* Account for name and ".". */ + if (statp->st_nlink < 2) + { + subdirs_unreliable = true; + } + else + { + subdirs_unreliable = false; /* not neccesarily right */ + subdirs_left = statp->st_nlink - 2; /* Account for name and ".". */ + } + errno = 0; dirinfo = xsavedir(name, 0); @@ -1910,7 +1923,7 @@ process_dir (char *pathname, char *name, int pathlen, struct stat *statp, char * strcpy (cur_name, namep); state.curdepth++; - if (!options.no_leaf_check) + if (!options.no_leaf_check && !subdirs_unreliable) { if (mode && S_ISDIR(mode) && (subdirs_left == 0)) { -- 2.11.4.GIT