Tests for module 'unicase/u16-is-uppercase'.
[gnulib.git] / lib / fts.c
index fdbe258..0cbb9fb 100644 (file)
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -618,8 +618,10 @@ fts_close (FTS *sp)
 
        fd_ring_clear (&sp->fts_fd_ring);
 
+#if GNULIB_FTS
        if (sp->fts_leaf_optimization_works_ht)
          hash_free (sp->fts_leaf_optimization_works_ht);
+#endif
 
        free_dir (sp);
 
@@ -717,6 +719,7 @@ static bool dirent_inode_sort_may_be_useful (int dir_fd) { return true; }
 static bool leaf_optimization_applies (int dir_fd) { return false; }
 #endif
 
+#if GNULIB_FTS
 /* link-count-optimization entry:
    map an stat.st_dev number to a boolean: leaf_optimization_works */
 struct LCO_ent
@@ -798,6 +801,7 @@ link_count_optimize_ok (FTSENT const *p)
 
   return opt_ok;
 }
+#endif
 
 /*
  * Special case of "/" at the end of the file name so that slashes aren't
@@ -961,7 +965,10 @@ check_for_dir:
                    if (p->fts_statp->st_size == FTS_STAT_REQUIRED)
                      {
                        FTSENT *parent = p->fts_parent;
-                       if (parent->fts_n_dirs_remaining == 0
+                       if (FTS_ROOTLEVEL < p->fts_level
+                           /* ->fts_n_dirs_remaining is not valid
+                              for command-line-specified names.  */
+                           && parent->fts_n_dirs_remaining == 0
                            && ISSET(FTS_NOSTAT)
                            && ISSET(FTS_PHYSICAL)
                            && link_count_optimize_ok (parent))
@@ -971,11 +978,10 @@ check_for_dir:
                        else
                          {
                            p->fts_info = fts_stat(sp, p, false);
-                           if (S_ISDIR(p->fts_statp->st_mode))
-                             {
-                               if (parent->fts_n_dirs_remaining)
+                           if (S_ISDIR(p->fts_statp->st_mode)
+                               && p->fts_level != FTS_ROOTLEVEL
+                               && parent->fts_n_dirs_remaining)
                                  parent->fts_n_dirs_remaining--;
-                             }
                          }
                      }
                    else