From owner-freebsd-hackers@FreeBSD.ORG Sat Jun 19 17:50:13 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6B44C16A4CE for ; Sat, 19 Jun 2004 17:50:13 +0000 (GMT) Received: from mta10-svc.ntlworld.com (mta10-svc.ntlworld.com [62.253.162.94]) by mx1.FreeBSD.org (Postfix) with ESMTP id 71CDE43D54 for ; Sat, 19 Jun 2004 17:50:10 +0000 (GMT) (envelope-from scott@fishballoon.org) Received: from llama.fishballoon.org ([81.104.195.124]) by mta10-svc.ntlworld.comESMTP <20040619174908.JOIY24992.mta10-svc.ntlworld.com@llama.fishballoon.org> for ; Sat, 19 Jun 2004 18:49:08 +0100 Received: from tuatara.fishballoon.org ([192.168.1.6]) by llama.fishballoon.org with esmtp (Exim 4.34 (FreeBSD)) id 1Bbjyi-000Kuo-BQ for freebsd-hackers@freebsd.org; Sat, 19 Jun 2004 18:50:08 +0100 Received: (from scott@localhost) by tuatara.fishballoon.org (8.12.11/8.12.11/Submit) id i5JHo7Ng028662 for freebsd-hackers@freebsd.org; Sat, 19 Jun 2004 18:50:07 +0100 (BST) (envelope-from scott) Date: Sat, 19 Jun 2004 18:50:07 +0100 From: Scott Mitchell To: freebsd-hackers@freebsd.org Message-ID: <20040619175007.GB462@tuatara.fishballoon.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="TB36FDmn/VVEgNH/" Content-Disposition: inline User-Agent: Mutt/1.4.2.1i X-Operating-System: FreeBSD 4.10-PRERELEASE i386 Subject: /bin/ls sorting bug? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Jun 2004 17:50:13 -0000 --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, ls(1) says that the -t option will: Sort by time modified (most recently modified first) before sort- ing the operands by lexicographical order. which I take to mean that items (in the same directory) with the same timestamp should be further sorted according to their names. Unfortunately it doesn't really work that way: (562) tuatara:/tmp/foo $ ls -lt total 0 -rw-rw-r-- 1 scott wheel 0 19 Jun 17:48 c -rw-rw-r-- 7 scott wheel 0 19 Jun 17:13 b -rw-rw-r-- 7 scott wheel 0 19 Jun 17:13 d -rw-rw-r-- 7 scott wheel 0 19 Jun 17:13 e -rw-rw-r-- 7 scott wheel 0 19 Jun 17:13 f -rw-rw-r-- 7 scott wheel 0 19 Jun 17:13 g -rw-rw-r-- 7 scott wheel 0 19 Jun 17:13 h -rw-rw-r-- 1 scott wheel 0 19 Jun 17:13 i -rw-rw-r-- 1 scott wheel 0 19 Jun 17:13 j -rw-rw-r-- 7 scott wheel 0 19 Jun 17:13 a -rw-rw-r-- 1 scott wheel 0 19 Jun 17:13 k This is on a 4.10-PRERELEASE machine, but the -CURRENT code seems to be identical as far as sorting goes. Is this intended behaviour? If so, the documentation is wrong. Otherwise, the attached patch produces the expected output. I can commit it if there are no objections. Scott -- =========================================================================== Scott Mitchell | PGP Key ID | "Eagles may soar, but weasels Cambridge, England | 0x54B171B9 | don't get sucked into jet engines" scott at fishballoon.org | 0xAA775B8B | -- Anon --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ls.patch" Index: cmp.c =================================================================== RCS file: /home/ncvs/src/bin/ls/cmp.c,v retrieving revision 1.9.2.2 diff -u -r1.9.2.2 cmp.c --- cmp.c 8 Jul 2002 06:59:27 -0000 1.9.2.2 +++ cmp.c 19 Jun 2004 16:54:55 -0000 @@ -67,35 +67,47 @@ int modcmp(const FTSENT *a, const FTSENT *b) { - return (b->fts_statp->st_mtime - a->fts_statp->st_mtime); + return (a->fts_statp->st_mtime == b->fts_statp->st_mtime ? + namecmp(a, b) : + b->fts_statp->st_mtime - a->fts_statp->st_mtime); } int revmodcmp(const FTSENT *a, const FTSENT *b) { - return (a->fts_statp->st_mtime - b->fts_statp->st_mtime); + return (a->fts_statp->st_mtime == b->fts_statp->st_mtime ? + revnamecmp(a, b) : + a->fts_statp->st_mtime - b->fts_statp->st_mtime); } int acccmp(const FTSENT *a, const FTSENT *b) { - return (b->fts_statp->st_atime - a->fts_statp->st_atime); + return (a->fts_statp->st_atime == b->fts_statp->st_atime ? + namecmp(a, b) : + b->fts_statp->st_atime - a->fts_statp->st_atime); } int revacccmp(const FTSENT *a, const FTSENT *b) { - return (a->fts_statp->st_atime - b->fts_statp->st_atime); + return (a->fts_statp->st_atime == b->fts_statp->st_atime ? + revnamecmp(a, b) : + a->fts_statp->st_atime - b->fts_statp->st_atime); } int statcmp(const FTSENT *a, const FTSENT *b) { - return (b->fts_statp->st_ctime - a->fts_statp->st_ctime); + return (a->fts_statp->st_ctime == b->fts_statp->st_ctime ? + namecmp(a, b) : + b->fts_statp->st_ctime - a->fts_statp->st_ctime); } int revstatcmp(const FTSENT *a, const FTSENT *b) { - return (a->fts_statp->st_ctime - b->fts_statp->st_ctime); + return (a->fts_statp->st_ctime == b->fts_statp->st_ctime ? + revnamecmp(a, b) : + a->fts_statp->st_ctime - b->fts_statp->st_ctime); } --TB36FDmn/VVEgNH/--