summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-07-25 00:00:19 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2017-07-25 00:27:47 -0700
commite66b0b94e7239fb47c9ccc2c704bb1149164d6ed (patch)
treedff5c7e27890a1737b1a8a53c4a882c3c5a5895b
parentb446700e06b71f8170c46371261e8334888df7f8 (diff)
fts: simplify fts_build
* lib/fts.c (fts_build): Simplify, and be lazier about calling leaf_optimization.
-rw-r--r--ChangeLog4
-rw-r--r--lib/fts.c40
2 files changed, 19 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index cbe4c9e..ae2b049 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2017-07-24 Paul Eggert <eggert@cs.ucla.edu>
+ fts: simplify fts_build
+ * lib/fts.c (fts_build): Simplify, and be lazier about
+ calling leaf_optimization.
+
fts: three levels of leaf optimization
* lib/fts.c (enum leaf_optimization): New type with three values.
(S_MAGIC_AFS): New macro. Sort them.
diff --git a/lib/fts.c b/lib/fts.c
index 663a09b..790f71c 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1326,8 +1326,6 @@ fts_build (register FTS *sp, int type)
bool descend;
bool doadjust;
ptrdiff_t level;
- nlink_t nlinks;
- bool nostat;
size_t len, maxlen, new_len;
char *cp;
int dir_fd;
@@ -1398,25 +1396,6 @@ fts_build (register FTS *sp, int type)
max_entries = sp->fts_compar ? SIZE_MAX : FTS_MAX_READDIR_ENTRIES;
/*
- * Nlinks is the number of possible entries of type directory in the
- * directory if we're cheating on stat calls, 0 if we're not doing
- * any stat calls at all, (nlink_t) -1 if we're statting everything.
- */
- if (type == BNAMES) {
- nlinks = 0;
- /* Be quiet about nostat, GCC. */
- nostat = false;
- } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)
- && leaf_optimization (cur) != NO_LEAF_OPTIMIZATION) {
- nlinks = (cur->fts_statp->st_nlink
- - (ISSET (FTS_SEEDOT) ? 0 : MIN_DIR_NLINK));
- nostat = true;
- } else {
- nlinks = -1;
- nostat = false;
- }
-
- /*
* If we're going to need to stat anything or we want to descend
* and stay in the directory, chdir. If this fails we keep going,
* but set a flag so we don't chdir after the post-order visit.
@@ -1437,7 +1416,18 @@ fts_build (register FTS *sp, int type)
the required dirp and dir_fd. */
descend = true;
}
- else if (nlinks || type == BREAD) {
+ else
+ {
+ /* Try to descend unless it is a names-only fts_children,
+ or the directory is a known to lack subdirectories. */
+ descend = (type != BNAMES
+ && ! (ISSET (FTS_NOSTAT) && ISSET (FTS_PHYSICAL)
+ && ! ISSET (FTS_SEEDOT)
+ && cur->fts_statp->st_nlink == MIN_DIR_NLINK
+ && (leaf_optimization (cur)
+ != NO_LEAF_OPTIMIZATION)));
+ if (descend || type == BREAD)
+ {
if (ISSET(FTS_CWDFD))
{
dir_fd = dup (dir_fd);
@@ -1445,7 +1435,7 @@ fts_build (register FTS *sp, int type)
set_cloexec_flag (dir_fd, true);
}
if (dir_fd < 0 || fts_safe_changedir(sp, cur, dir_fd, NULL)) {
- if (nlinks && type == BREAD)
+ if (descend && type == BREAD)
cur->fts_errno = errno;
cur->fts_flags |= FTS_DONTCHDIR;
descend = false;
@@ -1455,8 +1445,8 @@ fts_build (register FTS *sp, int type)
cur->fts_dirp = NULL;
} else
descend = true;
- } else
- descend = false;
+ }
+ }
/*
* Figure out the max file name length that can be stored in the