On 9/16/2014 4:00 PM, Ingo Schwarze wrote:
Hi,

On 9/15/2014 10:58 PM, William Orr wrote:

This diff adds a flag to du(1) to limit the depth of results
that are displayed to the user.

The semantics are equivalent to FreeBSD's, where it is mutually
exclusive with -a and -s, and du -d 0 is equivalent to du -s.

Thoughts?

I think it's a bad idea and i'd prefer to not have this flag.
It complicates the manual and code for almost no gain.

Unix tools are supposed to do one thing each, and do it well.
Selecting files out of a file hierarchy and providing options
for selection is the task of find(1), not du(1).  Doing what
you want is trivial combining find and -exec du, or find | xargs du.
What next?  du --flags --group --name --user?

However:

  * FreeBSD has it since 1996 (John-Mark Gurney is to blame for the bloat)
  * GNU coreutils has --max-depth since 1997 (Jim Meyering is to blame)
  * consequently, DragonFly has it forever (since 2003)
  * NetBSD has it since 2006 (Elad Efrat committed)
  * GNU coreutils has -d as an alias for --max-depth it since 2010

  * illumos (and OpenSolaris before it) has different semantics:
    illumos du -d is the same as BSD du -x
    That may be a Sun invention, i have no idea.
  * Neither SysV nor 4.4BSD had a -d option.
  * POSIX does not have it.

Even though it is not standardized, it seems so widespread by now
that i think we better follow, given that it's not actively harmful
and the bloat is relatively little: In my version of the patch,
the actual prtout() tests become *simpler* instead of more
complicated.

I polished the diff in the following ways:

  * The meaning of the depth argument is much easier to understand
    when we explicitly say that -d 0 is the same as -s.
  * "Grand total" is used in two different senses; downgrade the
    smaller one to just "total" to reduce potential for confusion.
  * Mention that -d is a POSIX extension.
  * Correct HISTORY: du is v1, not v3; and add missing history of
    options.  We are adding a new option, so it's a good time to do
    that.  HISTORY can be checked here:
    http://mdocml.bsd.lv/cgi-bin/man.cgi/history/man1/du.1
  * Simplify option handling: Delete two *flag variables instead
    of adding one.
  * Do not mix declarations and initialization.
  * Sort options in getopt(3).
  * Detect option clashes right away.  That's better because it
    also catches duplicate -d options.
  * No need to cast the strtonum(3) return value.
  * Avoid duplicate "invalid" in error message.
  * Avoid a few excessively long lines.

OK?
   Ingo

This seems to work the same in all of my test cases, and is *much* better than my original patch. Thanks for the polish!

P.S.
William, whitespace was mangled in your patch.

Serves me right for hurriedly copying the patch from a putty session when I realized I forgot to update usage().

Reply via email to