]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(process_file): If a file's size is not being counted
authorJim Meyering <jim@meyering.net>
Sat, 8 Mar 2003 10:21:19 +0000 (10:21 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 8 Mar 2003 10:21:19 +0000 (10:21 +0000)
e.g., because it's a hard link to a file we've already counted,
then don't print a line for it.

src/du.c

index 8a98aba84faebeb2d83f03e3d81915741f4c099b..6445f8e8a3878dea3dc2d528f6b88d04cb9e5536 100644 (file)
--- a/src/du.c
+++ b/src/du.c
@@ -321,6 +321,7 @@ process_file (const char *file, const struct stat *sb, int file_type,
   static size_t n_alloc;
   static uintmax_t *sum_ent;
   static uintmax_t *sum_subdir;
+  int print = 1;
 
   /* Always define info->skip before returning.  */
   info->skip = excluded_filename (exclude, file + info->base);
@@ -372,6 +373,7 @@ process_file (const char *file, const struct stat *sb, int file_type,
         We still have to update prev_level and maybe propagate
         some sums up the hierarchy.  */
       size = 0;
+      print = 0;
     }
   else
     {
@@ -453,6 +455,12 @@ process_file (const char *file, const struct stat *sb, int file_type,
   if (file_type == FTW_DNR || file_type == FTW_DCH)
     return 0;
 
+  /* If we're not counting an entry, e.g., because it's a hard link
+     to a file we've already counted (and --count-links), then don't
+     print a line for it.  */
+  if (!print)
+    return 0;
+
   /* FIXME: This looks suspiciously like it could be simplified.  */
   if ((IS_FTW_DIR_TYPE (file_type) &&
                     (info->level <= max_depth || info->level == 0))