coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Support for --size in du


From: Bernhard Voelker
Subject: Re: [PATCH] Support for --size in du
Date: Thu, 17 Jan 2013 02:23:18 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2

On 01/04/2012 07:18 PM, Pádraig Brady wrote:
> Sorry for the tardy response.
> This was actually proposed previously.
> http://lists.gnu.org/archive/html/bug-coreutils/2009-01/msg00105.html
> It's still a tempting option to add.
> Given the simplicity, and usefulness +1 from me.

"Liulk" reminded me off-list about this topic.
This was the conversation:

On 01/14/2013 02:30 AM, Bernhard Voelker wrote:> On 01/13/2013 06:34 AM, Likai 
Liu wrote:
>> Hi Bernhard,
>>
>> I noticed that at least two people have independently contributed their 
>> implementation of the --min-size option to du in
>> the past.
>>
>> http://lists.gnu.org/archive/html/bug-coreutils/2009-01/msg00105.html
>> http://lists.gnu.org/archive/html/coreutils/2011-10/msg00046.html
>>
>> And I was on my way to become the third one, except I realized none of their 
>> contributions made in to coreutils.
>>
>> Is there a reason for rejecting their patches, or do you have plans to 
>> incorporate them at some point?
>>
>> liulk
> 
> Hi Liulk,
> 
> thanks for the heads-up - I think we lost focus on this.
> The last reply on this was from Padraig:
> 
> http://lists.gnu.org/archive/html/coreutils/2012-01/msg00032.html
> 
> I'm working on a complete patch incl. tests and docs now
> and will post it on the mailing list soon.
> 
> Have a nice day,
> Berny


I was pretty sure that this slipped also from Padraig's list.
Therefore, I took Jakob's patch and amended it with documentation
and a comprehensive test. ;-)

In contrast to Jakob's version, I added code to handle the
special, invalid value "-0" ... and changed the usage a bit.

Please run the test on as many different file systems and OSs
as possible because I was not always sure about the block sizes
and the apparent sizes of directories (especially when they are
empty) ... the result with "-a" without also specifying "--apparent"
can be quite surprising sometimes. The test passed here on EXT4.

Have a nice day,
Berny

>From 8e3080999d8faa6df21b907be41f0a826300c59d Mon Sep 17 00:00:00 2001
From: Jakob Truelsen <address@hidden>
Date: Thu, 17 Jan 2013 02:07:23 +0100
Subject: [PATCH] du: add --size option

* src/du.c (opt_size): Add variable to hold the value of
the --size option specified by the user.
(SIZE_OPTION): Add enum.
(long_options): Add a required_argument entry for the new --size
option.
(usage): Add --size option.
(process_file): Elide printing the entry if its size does not
meet the value specified by the --size option.
(main): In the argument parsing loop, add a case for the new
SIZE_OPTION. Convert the given argument by permitting the well-
known suffixes for megabyte, gigabytes, etc.
Handle the special case "-0": give an error as this value is
not permitted.
* doc/coreutils.texi (du invocation): Add documentation for the
above new option.
* tests/du/size.sh: Add new test to exercise the new --size option.
* tests/local.mk (all_tests): Mention the above test.

Improved by: Bernhard Voelker <address@hidden>
---
 NEWS               |    3 +
 doc/coreutils.texi |   34 +++++
 src/du.c           |   35 +++++-
 tests/du/size.sh   |  351 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/local.mk     |    1 +
 5 files changed, 421 insertions(+), 3 deletions(-)
 create mode 100644 tests/du/size.sh

diff --git a/NEWS b/NEWS
index 754b2cf..f9c978b 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,9 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   to include in the output, or all available columns if the FIELD_LIST is
   omitted.  Note this enables df to output both block and inode fields 
together.

+  du now accepts the --size=SIZE option to restrict the output to entries with
+  such a minimum SIZE (or a maximum SIZE if it is negative).
+
 ** Bug fixes

   cp --no-preserve=mode now no longer exits non-zero.
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 45a4b3d..9463088 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -11005,6 +11005,40 @@ is at level 0, so @code{du --max-depth=0} is 
equivalent to @code{du -s}.

 @optSi

+@item --size=@var{size}
+@opindex --size
+Exclude entries based on a given @var{size} (@pxref{Block size}).
+
+If @var{size} is positive, then @command{du} will only print entries with a 
size
+greater than or equal to that.
+
+If @var{size} is negative, then @command{du} will only print entries with a 
size
+smaller than or equal to that.
+
+Although GNU @command{find} can be used to find files of a certain size,
+@command{du}'s @option{--size} option can be used to also filter directories
+based on a given size.
+
+Please note that the @option{--size} option can be combined with the above
+@option{--apparent-size} option, and in this case would elide entries based on
+its apparent size.  This makes most sense for files, i.e. when the @option{-a}
+is specified, too.
+
+Here's how you would use @option{--size} to find directories with a size 
greater
+than or equal to 200 megabytes:
+
+@example
+du --size=200MB
+@end example
+
+Here's how you would use @option{--size} to find directories and files - note
+the @option{-a} - with an apparent size smaller than or equal to 500 bytes:
+
+@example
+du -a --size=-500 --apparent-size
+@end example
+
+
 @item -s
 @itemx --summarize
 @opindex -s
diff --git a/src/du.c b/src/du.c
index 5d8acce..ec2bc10 100644
--- a/src/du.c
+++ b/src/du.c
@@ -147,6 +147,10 @@ static bool opt_separate_dirs = false;
    is at level 0, so 'du --max-depth=0' is equivalent to 'du -s'.  */
 static size_t max_depth = SIZE_MAX;

+/* Only output entries with at least this SIZE if positive,
+   or at most if negative.  See --size option.  */
+static intmax_t opt_size = 0;
+
 /* Human-readable options for output.  */
 static int human_output_opts;

@@ -193,7 +197,8 @@ enum
   HUMAN_SI_OPTION,
   FTS_DEBUG,
   TIME_OPTION,
-  TIME_STYLE_OPTION
+  TIME_STYLE_OPTION,
+  SIZE_OPTION
 };

 static struct option const long_options[] =
@@ -212,6 +217,7 @@ static struct option const long_options[] =
   {"human-readable", no_argument, NULL, 'h'},
   {"si", no_argument, NULL, HUMAN_SI_OPTION},
   {"max-depth", required_argument, NULL, 'd'},
+  {"size", required_argument, NULL, SIZE_OPTION},
   {"null", no_argument, NULL, '0'},
   {"no-dereference", no_argument, NULL, 'P'},
   {"one-file-system", no_argument, NULL, 'x'},
@@ -319,6 +325,8 @@ Mandatory arguments to long options are mandatory for short 
options too.\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\
+      --size=SIZE       exclude entries smaller than SIZE if positive, or\n\
+                          entries greater than SIZE if negative\n\
 "), stdout);
       fputs (_("\
       --time            show time of the last modification of any file in 
the\n\
@@ -579,8 +587,15 @@ process_file (FTS *fts, FTSENT *ent)
   duinfo_add (&tot_dui, &dui);

   if ((IS_DIR_TYPE (info) && level <= max_depth)
-      || ((opt_all && level <= max_depth) || level == 0))
-    print_size (&dui_to_print, file);
+      || (opt_all && level <= max_depth)
+      || level == 0)
+    {
+      /* Print or elide this entry according to the --size option.  */
+      if (opt_size < 0
+          ? dui_to_print.size <= -opt_size
+          : dui_to_print.size >= opt_size)
+        print_size (&dui_to_print, file);
+    }

   return ok;
 }
@@ -843,6 +858,20 @@ main (int argc, char **argv)
           time_style = optarg;
           break;

+        case SIZE_OPTION:
+          {
+            enum strtol_error e;
+            e = xstrtoimax (optarg, NULL, 0, &opt_size, "kKmMGTPEZY0");
+            if (e != LONGINT_OK)
+              xstrtol_fatal (e, oi, c, long_options, optarg);
+            if (opt_size == 0 && *optarg == '-')
+              {
+                /* Do not allow -0, as this wouldn't make sense anyway.  */
+                error (EXIT_FAILURE, 0, _("invalid --size argument '-0'"));
+              }
+          }
+          break;
+
         case_GETOPT_HELP_CHAR;

         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
diff --git a/tests/du/size.sh b/tests/du/size.sh
new file mode 100644
index 0000000..fe623aa
--- /dev/null
+++ b/tests/du/size.sh
@@ -0,0 +1,351 @@
+#!/bin/sh
+# Exercise du's --size option.
+
+# Copyright (C) 2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ du
+
+mkdir -p a/b a/c || framework_failure_
+
+touch            a/b/0 || framework_failure_
+printf '%1s' x > a/b/1 || framework_failure_
+printf '%2s' x > a/b/2 || framework_failure_
+printf '%3s' x > a/b/3 || framework_failure_
+
+Ba=$(stat --format="%B * %b" a     | xargs expr)
+Bb=$(stat --format="%B * %b" a/b   | xargs expr)
+Bc=$(stat --format="%B * %b" a/c   | xargs expr)
+B0=$(stat --format="%B * %b" a/b/0 | xargs expr)
+B1=$(stat --format="%B * %b" a/b/1 | xargs expr)
+B2=$(stat --format="%B * %b" a/b/2 | xargs expr)
+B3=$(stat --format="%B * %b" a/b/3 | xargs expr)
+
+Sa=$(stat --format=%s a    )
+Sb=$(stat --format=%s a/b  )
+Sc=$(stat --format=%s a/c  )
+S0=$(stat --format=%s a/b/0)
+S1=$(stat --format=%s a/b/1)
+S2=$(stat --format=%s a/b/2)
+S3=$(stat --format=%s a/b/3)
+
+Bb0123=$(expr $Bb + $B0 + $B1 + $B2 + $B3)
+Sb0123=$(expr $Sb + $S0 + $S1 + $S2 + $S3)
+
+Bab0123=$(expr $Ba + $Bc + $Bb0123)
+Sab0123=$(expr $Sa + $Sc + $Sb0123)
+
+# Sanity checks
+test $Ba -gt 4 || skip_ "block size of a directory is smaller than 4 bytes"
+test $Bc -gt 4 || skip_ "block size of an empty directory is smaller than 4 \
+bytes"
+test $Sa -gt 4 || skip_ "apparent size of a directory is smaller than 4 bytes"
+test $B1 -gt 4 || skip_ "block size of small file smaller than 4 bytes"
+test $S3 -eq 3 || framework_failure_
+test $S2 -eq 2 || framework_failure_
+test $S1 -eq 1 || framework_failure_
+test $S0 -eq 0 || framework_failure_
+test $B0 -eq 0 || skip_ "block size of an empty file unequal Zero"
+# block size of a/b/1 == a/b/2
+test $B1 -eq $B2 || framework_failure_
+# a is bigger than a/b.
+test $Sab0123 -gt $Sb0123 || framework_failure_
+test $Bab0123 -gt $Bb0123 || framework_failure_
+# a/b is bigger than empty a/c.
+test $Sb0123 -gt $Sc || framework_failure_
+test $Bb0123 -gt $Bc || framework_failure_
+
+# Exercise a bad argument: unparsable number.
+du --size=SIZE a > out 2>&1 && fail=1
+cat <<EOF > exp
+du: invalid --size argument 'SIZE'
+EOF
+compare exp out || fail=1
+rm -f out
+
+# Exercise a bad argument: -0 is not valid.
+du --size=-0 a > out 2>&1 && fail=1
+cat <<EOF > exp
+du: invalid --size argument '-0'
+EOF
+compare exp out || fail=1
+rm -f out
+
+# Exercise a bad argument: empty argument.
+du --size= a > out 2>&1 && fail=1
+cat <<EOF > exp
+du: invalid --size argument ''
+EOF
+compare exp out || fail=1
+rm -f out
+
+# Exercise a bad argument: no argument.
+du --size > out 2>&1 && fail=1
+cat <<EOF > exp
+du: option '--size' requires an argument
+Try 'du --help' for more information.
+EOF
+compare exp out || fail=1
+rm -f out
+
+dutest ()
+{
+  args="$1"
+  exp="$2"
+
+  rm -f exp out
+
+  # Expected output.
+  if [ "$exp" = "" ] ; then
+    touch exp
+  else
+    printf "%s " $exp | tr ' ' "\n" > exp
+  fi
+
+  rc=0
+  du -B1 $args a > out1 2>&1 || { cat out1 ; rc=1 ; }
+
+  # Remove the size column and sort the output.
+  sed 's/^[0-9]*\t//' < out1 | LANG=C sort -o out || framework_failure_
+
+  compare exp out || { cat out1 ; rc=1 ; }
+  return $rc
+}
+
+# Check numbers around the total size of the main directory 'a'.
+# One byte greater than 'a'.
+s=$(expr $Sab0123 + 1)  # apparent size
+dutest "--app       --size=$s"  ''                                  || fail=1
+dutest "--app -a    --size=$s"  ''                                  || fail=1
+dutest "--app    -S --size=$s"  ''                                  || fail=1
+dutest "--app -a -S --size=$s"  ''                                  || fail=1
+dutest "--app       --size=-$s" 'a a/b a/c'                         || fail=1
+dutest "--app -a    --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail=1
+dutest "--app    -S --size=-$s" 'a a/b a/c'                         || fail=1
+dutest "--app -a -S --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail=1
+s=$(expr $Bab0123 + 1)  # block size
+dutest "            --size=$s"  ''                                  || fail=1
+dutest "      -a    --size=$s"  ''                                  || fail=1
+dutest "         -S --size=$s"  ''                                  || fail=1
+dutest "      -a -S --size=$s"  ''                                  || fail=1
+dutest "            --size=-$s" 'a a/b a/c'                         || fail=1
+dutest "      -a    --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail=1
+dutest "         -S --size=-$s" 'a a/b a/c'                         || fail=1
+dutest "      -a -S --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail=1
+
+# Exactly the size of 'a'.
+s=$Sab0123  # apparent size
+dutest "--app       --size=$s"  'a'                                 || fail=1
+dutest "--app -a    --size=$s"  'a'                                 || fail=1
+dutest "--app    -S --size=$s"  ''                                  || fail=1
+dutest "--app -a -S --size=$s"  ''                                  || fail=1
+dutest "--app       --size=-$s" 'a a/b a/c'                         || fail=1
+dutest "--app -a    --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail=1
+dutest "--app    -S --size=-$s" 'a a/b a/c'                         || fail=1
+dutest "--app -a -S --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail=1
+s=$Bab0123  # block size
+dutest "            --size=$s"  'a'                                 || fail=1
+dutest "      -a    --size=$s"  'a'                                 || fail=1
+dutest "         -S --size=$s"  ''                                  || fail=1
+dutest "      -a -S --size=$s"  ''                                  || fail=1
+dutest "            --size=-$s" 'a a/b a/c'                         || fail=1
+dutest "      -a    --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail=1
+dutest "         -S --size=-$s" 'a a/b a/c'                         || fail=1
+dutest "      -a -S --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail=1
+
+# One byte smaller than 'a'.
+s=$(expr $Sab0123 - 1)  # apparent size
+dutest "--app       --size=$s"  'a'                                 || fail=1
+dutest "--app -a    --size=$s"  'a'                                 || fail=1
+dutest "--app    -S --size=$s"  ''                                  || fail=1
+dutest "--app -a -S --size=$s"  ''                                  || fail=1
+dutest "--app       --size=-$s" 'a/b a/c'                           || fail=1
+dutest "--app -a    --size=-$s" 'a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'   || fail=1
+dutest "--app    -S --size=-$s" 'a a/b a/c'                         || fail=1
+dutest "--app -a -S --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail=1
+s=$(expr $Bab0123 - 1)  # block size
+dutest "            --size=$s"  'a'                                 || fail=1
+dutest "      -a    --size=$s"  'a'                                 || fail=1
+dutest "         -S --size=$s"  ''                                  || fail=1
+dutest "      -a -S --size=$s"  ''                                  || fail=1
+dutest "            --size=-$s" 'a/b a/c'                           || fail=1
+dutest "      -a    --size=-$s" 'a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'   || fail=1
+dutest "         -S --size=-$s" 'a a/b a/c'                         || fail=1
+dutest "      -a -S --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail=1
+
+
+# Check numbers around the total size of the sub directory 'a/b'.
+# One byte greater than 'a/b'.
+s=$(expr $Sb0123 + 1)  # apparent size
+dutest "--app       --size=$s"  'a'                                 || fail=1
+dutest "--app -a    --size=$s"  'a'                                 || fail=1
+dutest "--app    -S --size=$s"  ''                                  || fail=1
+dutest "--app -a -S --size=$s"  ''                                  || fail=1
+dutest "--app       --size=-$s" 'a/b a/c'                           || fail=1
+dutest "--app -a    --size=-$s" 'a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'   || fail=1
+dutest "--app    -S --size=-$s" 'a a/b a/c'                         || fail=1
+dutest "--app -a -S --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c' || fail=1
+s=$(expr $Bb0123 + 1)  # block size
+dutest "            --size=$s"  'a'                                  || fail=1
+dutest "      -a    --size=$s"  'a'                                  || fail=1
+dutest "         -S --size=$s"  ''                                   || fail=1
+dutest "      -a -S --size=$s"  ''                                   || fail=1
+dutest "            --size=-$s" 'a/b a/c'                            || fail=1
+dutest "      -a    --size=-$s" 'a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'    || fail=1
+dutest "         -S --size=-$s" 'a a/b a/c'                          || fail=1
+dutest "      -a -S --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'  || fail=1
+
+# Exactly the size of 'a/b'.
+s=$Sb0123  # apparent size
+dutest "--app       --size=$s"  'a a/b'                              || fail=1
+dutest "--app -a    --size=$s"  'a a/b'                              || fail=1
+dutest "--app    -S --size=$s"  'a/b'                                || fail=1
+dutest "--app -a -S --size=$s"  'a/b'                                || fail=1
+dutest "--app       --size=-$s" 'a/b a/c'                            || fail=1
+dutest "--app -a    --size=-$s" 'a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'    || fail=1
+dutest "--app    -S --size=-$s" 'a a/b a/c'                          || fail=1
+dutest "--app -a -S --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'  || fail=1
+s=$Bb0123  # block size
+dutest "            --size=$s"  'a a/b'                              || fail=1
+dutest "      -a    --size=$s"  'a a/b'                              || fail=1
+dutest "         -S --size=$s"  'a/b'                                || fail=1
+dutest "      -a -S --size=$s"  'a/b'                                || fail=1
+dutest "            --size=-$s" 'a/b a/c'                            || fail=1
+dutest "      -a    --size=-$s" 'a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'    || fail=1
+dutest "         -S --size=-$s" 'a a/b a/c'                          || fail=1
+dutest "      -a -S --size=-$s" 'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'  || fail=1
+
+# One byte smaller than 'a/b'.
+s=$(expr $Sb0123 - 1)  # apparent size
+dutest "--app       --size=$s"  'a a/b'                              || fail=1
+dutest "--app -a    --size=$s"  'a a/b'                              || fail=1
+dutest "--app    -S --size=$s"  'a/b'                                || fail=1
+dutest "--app -a -S --size=$s"  'a/b'                                || fail=1
+dutest "--app       --size=-$s" 'a/c'                                || fail=1
+dutest "--app -a    --size=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "--app    -S --size=-$s" 'a a/c'                              || fail=1
+dutest "--app -a -S --size=-$s" 'a a/b/0 a/b/1 a/b/2 a/b/3 a/c'      || fail=1
+s=$(expr $Bb0123 - 1)  # block size
+dutest "            --size=$s"  'a a/b'                              || fail=1
+dutest "      -a    --size=$s"  'a a/b'                              || fail=1
+dutest "         -S --size=$s"  'a/b'                                || fail=1
+dutest "      -a -S --size=$s"  'a/b'                                || fail=1
+dutest "            --size=-$s" 'a/c'                                || fail=1
+dutest "      -a    --size=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "         -S --size=-$s" 'a a/c'                              || fail=1
+dutest "      -a -S --size=-$s" 'a a/b/0 a/b/1 a/b/2 a/b/3 a/c'      || fail=1
+
+
+# Check numbers around the total size of the files a/b/[0123]'.
+echo One byte greater than 'a/b/3'.
+s=$(expr $S3 + 1)  # apparent size
+dutest "--app       --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app -a    --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app    -S --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app -a -S --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app       --size=-$s" ''                                   || fail=1
+dutest "--app -a    --size=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3'            || fail=1
+dutest "--app    -S --size=-$s" ''                                   || fail=1
+dutest "--app -a -S --size=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3'            || fail=1
+s=$(expr $B3 + 1)  # block size
+dutest "            --size=$s"  'a a/b'                              || fail=1
+dutest "      -a    --size=$s"  'a a/b'                              || fail=1
+dutest "         -S --size=$s"  'a/b'                                || fail=1
+dutest "      -a -S --size=$s"  'a/b'                                || fail=1
+dutest "            --size=-$s" 'a/c'                                || fail=1
+dutest "      -a    --size=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "         -S --size=-$s" 'a a/c'                              || fail=1
+dutest "      -a -S --size=-$s" 'a a/b/0 a/b/1 a/b/2 a/b/3 a/c'      || fail=1
+
+# Exactly the size of 'a/b/3'.
+echo Exactly the size of 'a/b/3'.
+s=$S3  # apparent size
+dutest "--app       --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app -a    --size=$s"  'a a/b a/b/3 a/c'                    || fail=1
+dutest "--app    -S --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app -a -S --size=$s"  'a a/b a/b/3 a/c'                    || fail=1
+dutest "--app       --size=-$s" ''                                   || fail=1
+dutest "--app -a    --size=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3'            || fail=1
+dutest "--app    -S --size=-$s" ''                                   || fail=1
+dutest "--app -a -S --size=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3'            || fail=1
+s=$B3  # block size
+dutest "            --size=$s"  'a a/b a/c'                          || fail=1
+dutest "      -a    --size=$s"  'a a/b a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "         -S --size=$s"  'a a/b a/c'                          || fail=1
+dutest "      -a -S --size=$s"  'a a/b a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "            --size=-$s" 'a/c'                                || fail=1
+dutest "      -a    --size=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "         -S --size=-$s" 'a a/c'                              || fail=1
+dutest "      -a -S --size=-$s" 'a a/b/0 a/b/1 a/b/2 a/b/3 a/c'      || fail=1
+
+# Exactly the size of 'a/b/2'.
+echo Exactly the size of 'a/b/2'.
+s=$S2  # apparent size
+dutest "--app       --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app -a    --size=$s"  'a a/b a/b/2 a/b/3 a/c'              || fail=1
+dutest "--app    -S --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app -a -S --size=$s"  'a a/b a/b/2 a/b/3 a/c'              || fail=1
+dutest "--app       --size=-$s" ''                                   || fail=1
+dutest "--app -a    --size=-$s" 'a/b/0 a/b/1 a/b/2'                  || fail=1
+dutest "--app    -S --size=-$s" ''                                   || fail=1
+dutest "--app -a -S --size=-$s" 'a/b/0 a/b/1 a/b/2'                  || fail=1
+s=$B2  # block size
+dutest "            --size=$s"  'a a/b a/c'                          || fail=1
+dutest "      -a    --size=$s"  'a a/b a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "         -S --size=$s"  'a a/b a/c'                          || fail=1
+dutest "      -a -S --size=$s"  'a a/b a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "            --size=-$s" 'a/c'                                || fail=1
+dutest "      -a    --size=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "         -S --size=-$s" 'a a/c'                              || fail=1
+dutest "      -a -S --size=-$s" 'a a/b/0 a/b/1 a/b/2 a/b/3 a/c'      || fail=1
+
+# Exactly the size of 'a/b/1'.
+echo Exactly the size of 'a/b/1'.
+s=$S1  # apparent size
+dutest "--app       --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app -a    --size=$s"  'a a/b a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "--app    -S --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app -a -S --size=$s"  'a a/b a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "--app       --size=-$s" ''                                   || fail=1
+dutest "--app -a    --size=-$s" 'a/b/0 a/b/1'                        || fail=1
+dutest "--app    -S --size=-$s" ''                                   || fail=1
+dutest "--app -a -S --size=-$s" 'a/b/0 a/b/1'                        || fail=1
+s=$B1  # block size
+dutest "            --size=$s"  'a a/b a/c'                          || fail=1
+dutest "      -a    --size=$s"  'a a/b a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "         -S --size=$s"  'a a/b a/c'                          || fail=1
+dutest "      -a -S --size=$s"  'a a/b a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "            --size=-$s" 'a/c'                                || fail=1
+dutest "      -a    --size=-$s" 'a/b/0 a/b/1 a/b/2 a/b/3 a/c'        || fail=1
+dutest "         -S --size=-$s" 'a a/c'                              || fail=1
+dutest "      -a -S --size=-$s" 'a a/b/0 a/b/1 a/b/2 a/b/3 a/c'      || fail=1
+
+# Exactly the size of 'a/b/0'.
+echo Exactly the size of 'a/b/0'.
+s=$S0  # apparent size
+dutest "--app       --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app -a    --size=$s"  'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'  || fail=1
+dutest "--app    -S --size=$s"  'a a/b a/c'                          || fail=1
+dutest "--app -a -S --size=$s"  'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'  || fail=1
+# (maximum tests (-0) not possible).
+s=$B0  # block size
+dutest "            --size=$s"  'a a/b a/c'                          || fail=1
+dutest "      -a    --size=$s"  'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'  || fail=1
+dutest "         -S --size=$s"  'a a/b a/c'                          || fail=1
+dutest "      -a -S --size=$s"  'a a/b a/b/0 a/b/1 a/b/2 a/b/3 a/c'  || fail=1
+# (maximum tests (-0) not possible).
+
+Exit $fail
diff --git a/tests/local.mk b/tests/local.mk
index 2fe006d..39b002b 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -496,6 +496,7 @@ all_tests =                                 \
   tests/du/no-x.sh                             \
   tests/du/one-file-system.sh                  \
   tests/du/restore-wd.sh                       \
+  tests/du/size.sh                             \
   tests/du/slash.sh                            \
   tests/du/slink.sh                            \
   tests/du/trailing-slash.sh                   \
-- 
1.7.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]