Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bug#517558: coreutils: ls -v sorting broken: some dotfiles sort to the end

4 views
Skip to first unread message

Josh Triplett

unread,
Feb 28, 2009, 11:50:08 AM2/28/09
to
Package: coreutils
Version: 7.1-2
Severity: normal

Since upgrading to coreutils 7.1, ls -v no longer sorts correctly;
specifically, some dotfiles now appear at the end rather than with the
other dotfiles. I use LC_COLLATE=C, so this does not represent a locale
problem.

The correct sorting, with coreutils 6.10-6:

$ ls -a -v
.. .. .0 .9 .A .Z .a .z 0 9 A Z a z

The incorrect sorting, With coreutils 7.1-2:

$ ls -a -v
.. .A .Z .a .z 0 9 A Z a z .0 .9 ..

Notice that .0, .9, and .. moved to the end.

The NEWS file for coreutils says:

ls -v now uses filevercmp function as sort predicate (instead of strverscmp)

This seems like a likely culprit.

- Josh Triplett

-- System Information:
Debian Release: squeeze/sid
APT prefers unstable
APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.28-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages coreutils depends on:
ii libacl1 2.2.47-2 Access control list shared library
ii libattr1 1:2.4.43-2 Extended attribute shared library
ii libc6 2.9-4 GNU C Library: Shared libraries
ii libselinux1 2.0.71-1 SELinux shared libraries

coreutils recommends no packages.

coreutils suggests no packages.

-- no debconf information

--
To UNSUBSCRIBE, email to debian-bugs-...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Jim Meyering

unread,
Mar 7, 2009, 7:00:12 PM3/7/09
to
Josh Triplett wrote:
> Since upgrading to coreutils 7.1, ls -v no longer sorts correctly;
> specifically, some dotfiles now appear at the end rather than with the
> other dotfiles. I use LC_COLLATE=C, so this does not represent a locale
> problem.
>
> The correct sorting, with coreutils 6.10-6:
>
> $ ls -a -v
> .. .. .0 .9 .A .Z .a .z 0 9 A Z a z
>
> The incorrect sorting, With coreutils 7.1-2:
>
> $ ls -a -v
> .. .A .Z .a .z 0 9 A Z a z .0 .9 ..
>
> Notice that .0, .9, and .. moved to the end.

Thanks for the report.
That's been fixed in gnulib.
Here's what's going into coreutils:

>From c0dbba5fb795ee209e8513b6eaa756bc7d212bc0 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meye...@redhat.com>
Date: Sat, 7 Mar 2009 20:41:00 +0100
Subject: [PATCH] tests: ls -v: exercise the bug fixed by gnulib's new filevercmp

* tests/misc/ls-misc (version-sort): New test.
(mk_file): New function.
Reported by Josh Triplett in <http://bugs.debian.org/517558>.
Details in http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/16902
* NEWS (Bug fixes): Mention it.
---
NEWS | 3 +++
THANKS | 1 +
tests/misc/ls-misc | 25 +++++++++++++++++++++----
3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 0f6e853..63c7e19 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ GNU coreutils NEWS -*- outline -*-
The bug strikes only with both --recursive (-r, -R) and --link (-l).
[bug introduced in coreutils-7.1]

+ ls --sort=version (-v) sorted names beginning with "." inconsistently.
+ Now, names that start with "." are always listed before those that don't.
+
pr: fix the bug whereby --indent=N (-o) did not indent header lines
[bug introduced in coreutils-6.9.90]

diff --git a/THANKS b/THANKS
index e40d2b0..46d077b 100644
--- a/THANKS
+++ b/THANKS
@@ -290,6 +290,7 @@ Jon Peatfield J.S.Pe...@damtp.cam.ac.uk
Joost van Baal joo...@xs4all.nl
Jorge Stolfi sto...@ic.unicamp.br
Joseph S. Myers js...@cam.ac.uk
+Josh Triplett jo...@freedesktop.org
Joshua Hudson josh...@gmail.com
Josselin Mouette jo...@debian.org
Juan F. Codagnone ju...@arnet.com.ar
diff --git a/tests/misc/ls-misc b/tests/misc/ls-misc
index 5a93b51..b58949e 100755
--- a/tests/misc/ls-misc
+++ b/tests/misc/ls-misc
@@ -1,6 +1,6 @@
#!/usr/bin/perl

-# Copyright (C) 1998, 2000-2008 Free Software Foundation, Inc.
+# Copyright (C) 1998, 2000-2009 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
@@ -64,12 +64,20 @@ sub setuid_setup()
. "so can't run this test\n"), exit 77;
}

+sub mk_file(@)
+{
+ foreach my $f (@_)
+ {
+ open (F, '>', $f) && close F
+ or die "creating $f: $!\n";
+ }
+}
+
sub mkdir_d {mkdir 'd',0755 or die "d: $!\n"}
sub rmdir_d {rmdir 'd' or die "d: $!\n"}
my $mkdir = {PRE => sub {mkdir_d}};
my $rmdir = {POST => sub {rmdir_d}};
-my $mkdir_reg = {PRE => sub {mkdir_d; open (FH, '>d/f') && close FH
- or die "d/f: $!\n" }};
+my $mkdir_reg = {PRE => sub {mkdir_d; mk_file 'd/f' }};
my $rmdir_reg = {POST => sub {unlink 'd/f' or die "d/f: $!\n";
rmdir 'd' or die "d: $!\n"}};

@@ -100,10 +108,12 @@ my $rmdir_d_slink = {POST => sub {unlink 'd/s' or die "d/s: $!\n";
sub make_j_d ()
{
mkdir 'j', 0700 or die "creating j: $!\n";
- (open F, '>j/d') && close F or die "creating j/d: $!\n";
+ mk_file 'j/d';
chmod 0555, 'j/d' or die "making j/d executable: $!\n";
}

+my @v1 = qw(0 9 A Z a z);
+my @v_files = ((map { ".$_" } @v1), @v1);
my $exe_in_subdir = {PRE => sub { make_j_d (); push_ls_colors('ex=01;32') }};
my $remove_j = {POST => sub {unlink 'j/d' or die "j/d: $!\n";
rmdir 'j' or die "j: $!\n";
@@ -207,6 +217,13 @@ my @Tests =
# For 5.97 and earlier, --file-type acted like --indicator-style=slash.
['file-type', '--file-type d', {OUT => "s@\n"},
$mkdir_d_slink, $rmdir_d_slink],
+
+ # 7.1 had a regression in how -v -a ordered some files
+ ['version-sort', '-v -A ' . join (' ', @v_files),
+ {OUT => join ("\n", @v_files) . "\n"},
+ {PRE => sub { mk_file @v_files }},
+ {POST => sub { unlink @v_files }},
+ ],
);

# Start with an unset LS_COLORS environment variable.
--
1.6.2.rc1.285.gc5f54

0 new messages