From owner-freebsd-hackers@FreeBSD.ORG Sun Jun 20 08:59:26 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 83DA616A4CE for ; Sun, 20 Jun 2004 08:59:26 +0000 (GMT) Received: from salmon.maths.tcd.ie (salmon.maths.tcd.ie [134.226.81.11]) by mx1.FreeBSD.org (Postfix) with SMTP id C43AE43D2F for ; Sun, 20 Jun 2004 08:59:25 +0000 (GMT) (envelope-from dwmalone@maths.tcd.ie) Received: from walton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP id ; 20 Jun 2004 09:59:13 +0100 (BST) Date: Sun, 20 Jun 2004 09:59:12 +0100 From: David Malone To: Scott Mitchell Message-ID: <20040620085912.GA7301@walton.maths.tcd.ie> References: <20040619175007.GB462@tuatara.fishballoon.org> <414787887.20040619210137@andric.com> <20040619193545.GC462@tuatara.fishballoon.org> <14210101.20040619220601@andric.com> <20040619225229.GE462@tuatara.fishballoon.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040619225229.GE462@tuatara.fishballoon.org> User-Agent: Mutt/1.5.3i Sender: dwmalone@maths.tcd.ie cc: freebsd-hackers@freebsd.org cc: Dimitry Andric Subject: Re: /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: Sun, 20 Jun 2004 08:59:26 -0000 On Sat, Jun 19, 2004 at 11:52:29PM +0100, Scott Mitchell wrote: > On Sat, Jun 19, 2004 at 10:06:01PM +0200, Dimitry Andric wrote: > > Looking through ls source shows that the sorting is done by passing a > > comparison function to fts_open(3). In the case of sorting by > > modification time, the *only* comparison made is of the mtime fields: > > You did see the patch attached to my original post, right? It modifies all > of these comparison functions to sort the two items by name (or reverse > name) in the case that their timestamps are equal. Hi Scott, Could you produce a version of your patch that uses the nanoseconds field too? I produced the one below, but I think the style in your patch was nicer. Also, I wonder if the revblahcmp functions should just call blahcmp with their arguments reversed? David. Index: cmp.c =================================================================== RCS file: /cvs/FreeBSD-CVS/src/bin/ls/cmp.c,v retrieving revision 1.13 diff -u -r1.13 cmp.c --- cmp.c 6 Apr 2004 20:06:47 -0000 1.13 +++ cmp.c 19 Jun 2004 21:23:01 -0000 @@ -63,35 +63,107 @@ int modcmp(const FTSENT *a, const FTSENT *b) { - return (b->fts_statp->st_mtime - a->fts_statp->st_mtime); + if (b->fts_statp->st_mtimespec.tv_sec > + a->fts_statp->st_mtimespec.tv_sec) + return 1; + if (b->fts_statp->st_mtimespec.tv_sec < + a->fts_statp->st_mtimespec.tv_sec) + return -1; + if (b->fts_statp->st_mtimespec.tv_nsec > + a->fts_statp->st_mtimespec.tv_nsec) + return 1; + if (b->fts_statp->st_mtimespec.tv_nsec < + a->fts_statp->st_mtimespec.tv_nsec) + return -1; + return (strcoll(a->fts_name, b->fts_name)); } int revmodcmp(const FTSENT *a, const FTSENT *b) { - return (a->fts_statp->st_mtime - b->fts_statp->st_mtime); + if (a->fts_statp->st_mtimespec.tv_sec > + b->fts_statp->st_mtimespec.tv_sec) + return 1; + if (a->fts_statp->st_mtimespec.tv_sec < + b->fts_statp->st_mtimespec.tv_sec) + return -1; + if (a->fts_statp->st_mtimespec.tv_nsec > + b->fts_statp->st_mtimespec.tv_nsec) + return 1; + if (a->fts_statp->st_mtimespec.tv_nsec < + b->fts_statp->st_mtimespec.tv_nsec) + return -1; + return (strcoll(b->fts_name, a->fts_name)); } int acccmp(const FTSENT *a, const FTSENT *b) { - return (b->fts_statp->st_atime - a->fts_statp->st_atime); + if (b->fts_statp->st_atimespec.tv_sec > + a->fts_statp->st_atimespec.tv_sec) + return 1; + if (b->fts_statp->st_atimespec.tv_sec < + a->fts_statp->st_atimespec.tv_sec) + return -1; + if (b->fts_statp->st_atimespec.tv_nsec > + a->fts_statp->st_atimespec.tv_nsec) + return 1; + if (b->fts_statp->st_atimespec.tv_nsec < + a->fts_statp->st_atimespec.tv_nsec) + return -1; + return (strcoll(a->fts_name, b->fts_name)); } int revacccmp(const FTSENT *a, const FTSENT *b) { - return (a->fts_statp->st_atime - b->fts_statp->st_atime); + if (a->fts_statp->st_atimespec.tv_sec > + b->fts_statp->st_atimespec.tv_sec) + return 1; + if (a->fts_statp->st_atimespec.tv_sec < + b->fts_statp->st_atimespec.tv_sec) + return -1; + if (a->fts_statp->st_atimespec.tv_nsec > + b->fts_statp->st_atimespec.tv_nsec) + return 1; + if (a->fts_statp->st_atimespec.tv_nsec < + b->fts_statp->st_atimespec.tv_nsec) + return -1; + return (strcoll(b->fts_name, a->fts_name)); } int statcmp(const FTSENT *a, const FTSENT *b) { - return (b->fts_statp->st_ctime - a->fts_statp->st_ctime); + if (b->fts_statp->st_ctimespec.tv_sec > + a->fts_statp->st_ctimespec.tv_sec) + return 1; + if (b->fts_statp->st_ctimespec.tv_sec < + a->fts_statp->st_ctimespec.tv_sec) + return -1; + if (b->fts_statp->st_ctimespec.tv_nsec > + a->fts_statp->st_ctimespec.tv_nsec) + return 1; + if (b->fts_statp->st_ctimespec.tv_nsec < + a->fts_statp->st_ctimespec.tv_nsec) + return -1; + return (strcoll(a->fts_name, b->fts_name)); } int revstatcmp(const FTSENT *a, const FTSENT *b) { - return (a->fts_statp->st_ctime - b->fts_statp->st_ctime); + if (a->fts_statp->st_ctimespec.tv_sec > + b->fts_statp->st_ctimespec.tv_sec) + return 1; + if (a->fts_statp->st_ctimespec.tv_sec < + b->fts_statp->st_ctimespec.tv_sec) + return -1; + if (a->fts_statp->st_ctimespec.tv_nsec > + b->fts_statp->st_ctimespec.tv_nsec) + return 1; + if (a->fts_statp->st_ctimespec.tv_nsec < + b->fts_statp->st_ctimespec.tv_nsec) + return -1; + return (strcoll(b->fts_name, a->fts_name)); }