du: print size (probably incomplete) of each inaccessible directory
authorJim Meyering <jim@meyering.net>
Tue, 31 Jul 2007 08:46:31 +0000 (10:46 +0200)
committerJim Meyering <jim@meyering.net>
Tue, 31 Jul 2007 10:10:11 +0000 (12:10 +0200)
 * src/du.c (process_file): Print what we know of the size of a
 directory even when it is inaccessible.  What we print is just the
 size of the directory itself, not counting any of its contents.
 * tests/du/inacc-dir: Test for this.
 * NEWS: Mention this change.

Signed-off-by: Jim Meyering <jim@meyering.net>
ChangeLog
NEWS
src/du.c
tests/du/inacc-dir

index 4168643..4d19371 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2007-07-31  Jim Meyering  <jim@meyering.net>
 
+       du: print size (probably incomplete) of each inaccessible directory
+       * src/du.c (process_file): Print what we know of the size of a
+       directory even when it is inaccessible.  What we print is just the
+       size of the directory itself, not counting any of its contents.
+       * tests/du/inacc-dir: Test for this.
+       * NEWS: Mention this change.
+
        Add a test for du not counting size of inaccessible directories.
        * tests/du/inacc-dir: New file. Test for fts.c bug fixed yesterday.
        * tests/du/Makefile.am (TESTS): Add inacc-dir.
diff --git a/NEWS b/NEWS
index 5c06c25..83d06b7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -83,6 +83,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   du -s now includes the size of any stat'able-but-inaccessible directory
   in the total size.
 
+  du (without -s) prints whatever it knows of the size of an inaccessible
+  directory.  Before, du would print nothing for such a directory.
+
   ls -x DIR would sometimes output the wrong string in place of the
   first entry.  [introduced in coreutils-6.8]
 
index 57678d9..f9bd2e3 100644 (file)
--- a/src/du.c
+++ b/src/du.c
@@ -596,14 +596,9 @@ process_file (FTS *fts, FTSENT *ent)
     duinfo_add (&dulvl[level].ent, &dui);
 
   /* Even if this directory is unreadable or we can't chdir into it,
-     do let its size contribute to the total, ... */
+     do let its size contribute to the total. */
   duinfo_add (&tot_dui, &dui);
 
-  /* ... but don't print out a total for it, since without the size(s)
-     of any potential entries, it could be very misleading.  */
-  if (ent->fts_info == FTS_DNR)
-    return ok;
-
   /* 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.  */
index 3bfbdef..add9293 100755 (executable)
@@ -45,4 +45,15 @@ du -s a > out 2> /dev/null && fail=1
 cmp out exp || fail=1
 test $fail = 1 && diff out exp 2> /dev/null
 
+# Same as above, but don't use -s, so we print
+# an entry for the unreadable "sub", too.
+chmod 700 a/sub || fail=1
+du -k a > exp || fail=1
+chmod 0 a/sub || fail=1
+# Expect failure, ignore diagnostics.
+du -k a > out 2> /dev/null && fail=1
+
+cmp out exp || fail=1
+test $fail = 1 && diff out exp 2> /dev/null
+
 (exit $fail); exit $fail