]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: Fix bug where --batch-size option shrank SORT_SIZE.
authorBo Borgerson <gigabo@gmail.com>
Thu, 19 Jun 2008 19:37:21 +0000 (15:37 -0400)
committerJim Meyering <meyering@redhat.com>
Fri, 20 Jun 2008 06:47:28 +0000 (08:47 +0200)
* src/sort.c (specify_nmerge, main): Only adjust SORT_SIZE if it's already set.
* tests/misc/sort-merge: Test bug fix.

src/sort.c
tests/misc/sort-merge

index 13935218ab921c92326c7b7698f247b4255b3ede..2039dabf8b4266f831cce32da5beadbe7a87f486 100644 (file)
@@ -1105,14 +1105,7 @@ specify_nmerge (int oi, char c, char const *s)
              e = LONGINT_OVERFLOW;
            }
          else
-           {
-             /* Need to re-check that we meet the minimum
-                requirement for memory usage with the new,
-                potentially larger, nmerge. */
-             sort_size = MAX (sort_size, MIN_SORT_SIZE);
-
-             return;
-           }
+           return;
        }
     }
 
@@ -3320,6 +3313,11 @@ main (int argc, char **argv)
       files = &minus;
     }
 
+  /* Need to re-check that we meet the minimum requirement for memory
+     usage with the final value for NMERGE. */
+  if (0 < sort_size)
+    sort_size = MAX (sort_size, MIN_SORT_SIZE);
+
   if (checkonly)
     {
       if (nfiles > 1)
index a2524c40c350b1d4dae16ac5b43004e8f3ea2030..fb7c63cc13e3d38008a647cb8754a4354da68618 100755 (executable)
@@ -27,6 +27,8 @@ my $prog = 'sort';
 # three empty files and one that says 'foo'
 my @inputs = (+(map{{IN=> {"empty$_"=> ''}}}1..3), {IN=> {foo=> "foo\n"}});
 
+my $big_input = "aaa\n" x 1024;
+
 # don't need to check for existence, since we're running in a temp dir
 my $badtmp = 'does/not/exist';
 
@@ -66,6 +68,11 @@ my @Tests =
      ['nmerge-no', "-m --batch-size=2 -T$badtmp", @inputs,
         {ERR_SUBST=>"s|: $badtmp/sort.+||"},
         {ERR=>"$prog: cannot create temporary file\n"}, {EXIT=>2}],
+
+     # This used to fail because setting batch-size without also setting
+     # buffer size would cause the buffer size to be set to the minimum.
+     ['batch-size', "--batch-size=16 -T$badtmp", {IN=> {big=> $big_input}},
+       {OUT=>$big_input}],
     );
 
 my $save_temps = $ENV{DEBUG};