Subject: Re: bug#17546: Problem with du

From: Eric Blake <[email-masked]>
Date: Thu, 22 May 2014 11:06:10 -0600

On 05/22/2014 10:21 AM, Dale R. Worley wrote:
>> From: Paul Eggert <[email-masked]>
> 
>> As far as I can see, POSIX doesn't allow the old behavior, but does 
>> allow the new one.
> 
> I looked at what I think is the Posix spec for du
> (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/du.html#tag_20_36),
> and I don't see anything that covers the situation one way or another,
> but there may be additional relevant information that I'm not aware
> of.

Yes, here's the additional relevant information:

http://austingroupbugs.net/view.php?id=527

Change line 84170 [du DESCRIPTION] from:

      Files with multiple links shall be counted and written
      for only one entry.

    to:

      A file that occurs multiple times under one file
      operand and that has a link count greater than 1 shall
      be counted and written for only one entry. It is
      implementation-defined whether a file that has a link
      count no greater than 1 is counted and written just
      once, or is counted and written for each occurrence.
      It is implementation-defined whether a file that
      occurs under one file operand is counted for other
      file operands.

In FUTURE DIRECTIONS, change line 84274 from "None" to
     "A future version of this standard may require that
      a file that occurs multiple times shall be counted and
      written for only one entry, even if the occurrences
      are under different file operands."

Change line 84177 [du OPTIONS] from:

    Regardless of the presence of the -a option,
    non-directories given as file operands shall always
    be listed.

  to:

    The -a option does not affect whether
    non-directories given as file operands are listed.

> 
>>> This leads to startlingly odd behaviors
>>
>> Any choice of behavior for 'du' will lead to odd behaviors sometimes, 
>> and there's no way we can make everybody happy in all cases.  There is 
>> an important technical advantage of du's current behavior, though; you 
>> can get the behavior you prefer by running "du X; du Y".  If we chaned 
>> du to reset itself between command-line arguments, there'd be no way to 
>> get the behavior I prefer, which is to count files just once.
> 
> OTOH, what I want "du *" to generate has to be done with "for F in * ;
> do du $F ; done", which is pretty annoying.
> 
> I'd like to suggest adding another option to du to establish the
> behavior I want.  It would be a weaker-grade of -l.  (I shouldn't have
> any trouble writing the code for that.)  Also, I think a few
> additional sentences in the manual page would make du's behavior
> clearer.
> 
> Dale
> 
> 
> 
> 
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org