summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Ringuette <jonr@scharp.org>2010-05-18 08:26:11 +0200
committerJim Meyering <meyering@redhat.com>2010-05-19 07:28:16 +0200
commit2b8ecfa6f14db48fbc204b2fc4993de077289c2d (patch)
tree8a4b21f3e6de2d934934f20848e83d86387518ff
parent1be4f180f5395b9ef89ab9166e33ba9a54cfba8b (diff)
downloadcoreutils-2b8ecfa6f14db48fbc204b2fc4993de077289c2d.tar.xz
du: recognize -d N as equivalent to --max-depth=N
* NEWS (New features): Mention it. * src/du.c (DEBUG_OPT): Remove. Use long-named ---debug instead. Commented out. (MAX_DEPTH_OPTION): Remove. Use 'd' instead. (main): Insert literal "d:"; remove DEBUG_OPT. * doc/coreutils.texi (du invocation): Add -d to indices. * tests/du/max-depth: Exercise -d, too.
-rw-r--r--NEWS3
-rw-r--r--doc/coreutils.texi2
-rw-r--r--src/du.c15
-rwxr-xr-xtests/du/max-depth7
4 files changed, 19 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index 5d7b81f97..19436fe44 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ GNU coreutils NEWS -*- outline -*-
** New features
+ du recognizes -d N as equivalent to --max-depth=N, for compatibility
+ with FreeBSD.
+
sort now accepts the --debug option, to highlight the part of the
line significant in the sort, and warn about questionable options.
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 77434e972..115e5fb49 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -10427,7 +10427,9 @@ This option is equivalent to @option{--block-size=1M}.
For each symbolic links encountered by @command{du},
consider the disk space used by the symbolic link.
+@item -d @var{depth}
@item --max-depth=@var{depth}
+@opindex -d @var{depth}
@opindex --max-depth=@var{depth}
@cindex limiting output of @command{du}
Show the total for each directory (and file if --all) that is at
diff --git a/src/du.c b/src/du.c
index 907ad79ed..5d83dc6b5 100644
--- a/src/du.c
+++ b/src/du.c
@@ -56,10 +56,8 @@ extern bool fts_debug;
#if DU_DEBUG
# define FTS_CROSS_CHECK(Fts) fts_cross_check (Fts)
-# define DEBUG_OPT "d"
#else
# define FTS_CROSS_CHECK(Fts)
-# define DEBUG_OPT
#endif
/* Initial size of the hash table. */
@@ -192,7 +190,7 @@ enum
EXCLUDE_OPTION,
FILES0_FROM_OPTION,
HUMAN_SI_OPTION,
- MAX_DEPTH_OPTION,
+ FTS_DEBUG,
TIME_OPTION,
TIME_STYLE_OPTION
};
@@ -204,6 +202,7 @@ static struct option const long_options[] =
{"block-size", required_argument, NULL, 'B'},
{"bytes", no_argument, NULL, 'b'},
{"count-links", no_argument, NULL, 'l'},
+ /* {"-debug", no_argument, NULL, FTS_DEBUG}, */
{"dereference", no_argument, NULL, 'L'},
{"dereference-args", no_argument, NULL, 'D'},
{"exclude", required_argument, NULL, EXCLUDE_OPTION},
@@ -211,7 +210,7 @@ static struct option const long_options[] =
{"files0-from", required_argument, NULL, FILES0_FROM_OPTION},
{"human-readable", no_argument, NULL, 'h'},
{"si", no_argument, NULL, HUMAN_SI_OPTION},
- {"max-depth", required_argument, NULL, MAX_DEPTH_OPTION},
+ {"max-depth", required_argument, NULL, 'd'},
{"null", no_argument, NULL, '0'},
{"no-dereference", no_argument, NULL, 'P'},
{"one-file-system", no_argument, NULL, 'x'},
@@ -312,7 +311,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
-x, --one-file-system skip directories on different file systems\n\
-X, --exclude-from=FILE exclude files that match any pattern in FILE\n\
--exclude=PATTERN exclude files that match PATTERN\n\
- --max-depth=N print the total for a directory (or file, with --all)\n\
+ -d, --max-depth=N print the total for a directory (or file, with --all)\n\
only if it is N or fewer levels below the command\n\
line argument; --max-depth=0 is the same as\n\
--summarize\n\
@@ -694,7 +693,7 @@ main (int argc, char **argv)
for (;;)
{
int oi = -1;
- int c = getopt_long (argc, argv, DEBUG_OPT "0abchHklmsxB:DLPSX:",
+ int c = getopt_long (argc, argv, "0abd:chHklmsxB:DLPSX:",
long_options, &oi);
if (c == -1)
break;
@@ -702,7 +701,7 @@ main (int argc, char **argv)
switch (c)
{
#if DU_DEBUG
- case 'd':
+ case FTS_DEBUG:
fts_debug = true;
break;
#endif
@@ -744,7 +743,7 @@ main (int argc, char **argv)
output_block_size = 1024;
break;
- case MAX_DEPTH_OPTION: /* --max-depth=N */
+ case 'd': /* --max-depth=N */
{
unsigned long int tmp_ulong;
if (xstrtoul (optarg, NULL, 0, &tmp_ulong, NULL) == LONGINT_OK
diff --git a/tests/du/max-depth b/tests/du/max-depth
index 4ddb6b7c9..ec22989c7 100755
--- a/tests/du/max-depth
+++ b/tests/du/max-depth
@@ -28,4 +28,11 @@ cut -f2- out > k && mv k out
compare out exp || fail=1
compare err /dev/null || fail=1
+# Repeat, but use -d 1.
+printf 'a/b\na\n' > exp || framework_failure_
+du -d 1 a > out 2>err || fail=1
+cut -f2- out > k && mv k out
+compare out exp || fail=1
+compare err /dev/null || fail=1
+
Exit $fail