Bug 250089

Summary: du doesn't report size of unreadable sub directories
Product: [Fedora] Fedora Reporter: Tim Waugh <twaugh>
Component: coreutilsAssignee: Ondrej Vasik <ovasik>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: medium    
Version: rawhideCC: meyering
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2007-11-02 10:44:42 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Bug Depends On: 250077    
Bug Blocks: 235704    

Description Tim Waugh 2007-07-30 09:56:59 EDT
Also affects Fedora.

+++ This bug was initially created as a clone of Bug #250077 +++

Description of problem:

When using du against a directory target that contains, whithin its tree,
non-accessible directories, du will not report the size of these. Since stat can
get the size, du should do it as well. Moreover, in the code it seems that this
was the intention, but a code bug has prevented this tool to report the size of
these directories:

--
                } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
                        if (ISSET(FTS_STOP))
                                return (NULL);
                        /* If fts_build's call to fts_safe_changedir failed
                           because it was not able to fchdir into a
                           subdirectory, tell the caller.  */

 			   because it was not able to fchdir into a
 			   subdirectory, tell the caller.  */
 			if (p->fts_errno)
-				p->fts_info = FTS_ERR;
+				if (p->fts_info != FTS_DNR)
+			    		p->fts_info = FTS_ERR;
 			/* FIXME: see if this should be in an else block */
 			LEAVE_DIR (sp, p, "2");
 			return (p);
--

fts_build will return NULL on problems, and if it couldn't opendir() a directory
it will set the flag fts_info to FTS_DNR which is an unreadable directory.
So not checking if we just reset the flag and avoid counting the size of that
directory, however, if we remember it, we can then stat and count its size.

Version-Release number of selected component (if applicable):
5.2.1

How reproducible:
Always

Steps to Reproduce:

1. cd /tmp
2. mkdir -p du_test/unreadable
3. du -a -b du_test
   4096    du_test/unreadable
   8192    du_test
4. chmod 000 du_test/unreadable
5. du -b -a du_test
   du: `du_test/unreadable': Permission denied
   4096    du_test
  
Actual results:
   du: `du_test/unreadable': Permission denied
   4096    du_test

Only the directories that can be readable are counted.

Expected results:
  du test
  4       test/dir
  du: cannot read directory `test/unreachable-dir': Permission denied
  12      test

Additional info:
Patch attached by Bryan Mason <bjmason@redhat.com>

Let me know if you need anything else,

-- Additional comment from jplans@redhat.com on 2007-07-30 07:47 EST --
Created an attachment (id=160237)
Fix report size of unredable subdirectories.


-- Additional comment from meyering@redhat.com on 2007-07-30 08:10 EST --
Nice one!  Thanks.
That's a bug upstream, too.
Comment 1 Ondrej Vasik 2007-11-02 10:44:42 EDT
Built in devel branch as coreutils-6.9-12.fc9, will build for older Fedoras with
some other fixes few days later. Closing RAWHIDE.