bug-coreutils
[Top][All Lists]
Advanced

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

Re: bug in ls -1U: argument files printed after their contents


From: Jim Meyering
Subject: Re: bug in ls -1U: argument files printed after their contents
Date: Sat, 25 Jul 2009 16:36:13 +0200

Kamil Dudka wrote:

> On Friday 24 of July 2009 21:49:35 Julian Bradfield wrote:
>> This hit me with the RH EL5 package coreutils-5.97-19.el5 .
>> I also see it in a build from clean coreutils-7.4 GNU release.
>>
>> Problem: when printing files with the -1U options, and more than one
>> file is given on the command line, the argument files are printed
>> after their contents instead of before.
>>
>> Transcript demonstrating bug:
>> -------------------------------------------
>> krk: mkdir /tmp/LSBUG
>> krk: mkdir /tmp/LSBUG/a
>> krk: mkdir /tmp/LSBUG/b
>> krk: touch /tmp/LSBUG/a/1
>> krk: /bin/ls -1U /tmp/LSBUG/a /tmp/LSBUG/b
>> 1
>> /tmp/LSBUG/a:
>>
>> /tmp/LSBUG/b:
>> krk:
>> -------------------------------------------
>>
>> Of course, this breaks any script that relies on that format, as well
>> as baffling human users. Since this bug doesn't seem to have been
>> reported yet, I guess I must be the only person left on the planet
>> running a 15-year old Cnews suite, where the expire script relies on
>> it and completely breaks.
>>
>> Since I see it in RH 5.97-19, which includes the "lsmemoryexhausted"
>> patch:
>>   author     Kamil Dudka <address@hidden>    2008-07-30 12:31:50 (GMT)
>>   committer     Jim Meyering <address@hidden>   2008-08-01 06:36:38
>> (GMT) commit 8d974b00fbbc2025de63e1e6d54827648fefa1c4 (patch)
>>   tree       bff56540d745da7ec4287455eaf3ad119bae5441
>>   parent     b44f5f74aa1cb209720cbb2cd60ecd47975397ab (diff)
>>
>> and I don't see in GNU 6.12, which doesn't include that patch, and I
>> do see it in GNU 7.4, which does, and the patch is obviously relevant,
>> I blame that patch.
>
> I agree. It behaves a bit different than we would expect to. Generally we have
> two possible solutions. We can either turn the optimization off when there
> are more than one files given as ls' argument. Or we can make it working even
> in that case. I'll look at it next week.

Thanks.
In the mean time, I've written a test for this.
Along the way, I noticed that ls -UR1 no longer works the
way I would expect, since the -R is effectively ignored.
This suggests that we may want to disable the optimization also
when -R is specified.

>From e6175ff3629d02575dfcd3c16606f819ce3ebc24 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 25 Jul 2009 11:06:22 +0200
Subject: [PATCH] tests: new test for bug in ls -1U dir arg ...

* tests/misc/ls-misc (multi-arg-U1): New test.
The bug was introduced in coreutils-7.0 via commit
8d974b00, 2008-07-30, "ls -U1 now uses constant memory".
Reported by Julian Bradfield.
* NEWS (Bug fixes): Mention it.
---
 NEWS               |    8 ++++++--
 THANKS             |    1 +
 tests/misc/ls-misc |   15 +++++++++++++--
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 6190895..c98d64d 100644
--- a/NEWS
+++ b/NEWS
@@ -4,14 +4,18 @@ GNU coreutils NEWS                                    -*- 
outline -*-

 ** Bug fixes

-  truncate -s failed to skip all whitespace in the option argument in
-  some locales.
+  ls -1U (with two or more arguments, at least one a nonempty directory)
+  would print entry names *before* the name of the containing directory.
+  [introduced in coreutils-7.0]

   sort now correctly ignores fields whose ending position is specified
   before the start position. Previously in numeric mode the remaining
   part of the line after the start position was used as the sort key.
   [This bug appears to have been present in "the beginning".]

+  truncate -s failed to skip all whitespace in the option argument in
+  some locales.
+
 ** New programs

   stdbuf: A new program to run a command with modified stdio buffering
diff --git a/THANKS b/THANKS
index bcd88f0..9115528 100644
--- a/THANKS
+++ b/THANKS
@@ -300,6 +300,7 @@ Joshua Hudson                       address@hidden
 Josselin Mouette                    address@hidden
 Juan F. Codagnone                   address@hidden
 Juan M. Guerrero                    address@hidden
+Julian Bradfield                    address@hidden
 Jungshik Shin                       address@hidden
 Jürgen Fluk                         address@hidden
 Jurriaan                            address@hidden
diff --git a/tests/misc/ls-misc b/tests/misc/ls-misc
index 30eb06c..bcd64e3 100755
--- a/tests/misc/ls-misc
+++ b/tests/misc/ls-misc
@@ -18,6 +18,7 @@
 use strict;

 (my $program_name = $0) =~ s|.*/||;
+my $prog = 'ls';

 # Turn off localization of executable's output.
 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
@@ -224,6 +225,18 @@ my @Tests =
       {PRE => sub { mk_file @v_files }},
       {POST => sub { unlink @v_files }},
       ],
+
+     # Test for the ls -1U bug fixed in coreutils-7.5.
+     # It is triggered only with -1U and with two or more arguments,
+     # at least one of which is a nonempty directory.
+     ['multi-arg-U1', '-U1 d no-such',
+      {OUT => "d:\nf\n"},
+      {ERR_SUBST=>'s/ch:.*/ch:/'},
+      {ERR => "$prog: cannot access no-such:\n"},
+      $mkdir_reg,
+      $rmdir_reg,
+      {EXIT => 2},
+     ],
     );

 # Start with an unset LS_COLORS environment variable.
@@ -232,8 +245,6 @@ delete $ENV{LS_COLORS};
 my $save_temps = $ENV{SAVE_TEMPS};
 my $verbose = $ENV{VERBOSE};

-my $prog = 'ls';
-
 setuid_setup;
 my $fail = run_tests ($program_name, $prog, address@hidden, $save_temps, 
$verbose);
 $fail
--
1.6.4.rc2.182.g24de1




reply via email to

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