From roberte@ghost.mep.ruhr-uni-bochum.de  Tue Sep 16 16:18:55 1997
Received: from ghost.mep.ruhr-uni-bochum.de (ghost.mep.ruhr-uni-bochum.de [134.147.6.33])
          by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id QAA26313
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 16 Sep 1997 16:18:52 -0700 (PDT)
Received: (from roberte@localhost)
          by ghost.mep.ruhr-uni-bochum.de (8.8.5/8.8.4)
	  id BAA19822; Wed, 17 Sep 1997 01:18:51 +0200 (MESZ)
Message-Id: <199709162318.BAA19822@ghost.mep.ruhr-uni-bochum.de>
Date: Wed, 17 Sep 1997 01:18:51 +0200 (MESZ)
From: Robert Eckardt <roberte@MEP.Ruhr-Uni-Bochum.de>
Reply-To: roberte@MEP.Ruhr-Uni-Bochum.de
To: FreeBSD-gnats-submit@freebsd.org
Subject: ls -d does not sort directories as plain files
X-Send-Pr-Version: 3.2

>Number:         4558
>Category:       bin
>Synopsis:       ls -d does not sort directories as plain files
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 16 16:20:00 PDT 1997
>Closed-Date:    Wed Sep 17 23:43:23 1997
>Last-Modified:  Wed Sep 17 23:44:58 PDT 1997
>Originator:     Robert Eckardt
>Release:        FreeBSD 2.2.2-RELEASE i386
>Organization:
>Environment:

	System from WC's 2.2.2 CD

>Description:

	As documented in the man page ls's option `-d' should list
	directories as plain files. Therefore, one would expect that
	files and directories are sorted on an equal footing (as it
	is on SunOS5.4, AIX, Linux).
	However, the (sorted) directories are appended after the
	sorted files.
	I don't know whether this behaviour is considered `classic',
	but it is inconsistent and surprising.

>How-To-Repeat:

# cd to_an_empty_test_directory
# touch a c
# mkdir b
# ls -l
total 1
-rw-rw-r--  1 roberte  work    0 17 Sep 00:58 a
drwxrwxr-x  2 roberte  work  512 17 Sep 00:58 b
-rw-rw-r--  1 roberte  work    0 17 Sep 00:58 c
# ls -ld *
-rw-rw-r--  1 roberte  work    0 17 Sep 00:58 a
-rw-rw-r--  1 roberte  work    0 17 Sep 00:58 c
drwxrwxr-x  2 roberte  work  512 17 Sep 00:58 b

>Fix:
	
	

>Release-Note:
>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: sef
State-Changed-When: Wed Sep 17 23:43:23 1997
State-Changed-Why:
I just checked in a diff for this.  (Okay, this isn't the exact diff I
checked in, this is the patch I got from Keith.  But it applied cleanly :).)


Index: ls.c
===================================================================
RCS file: /master/bin/ls/ls.c,v
retrieving revision 2.3
retrieving revision 2.4
diff -c -r2.3 -r2.4
*** ls.c	1996/01/09 21:14:03	2.3
--- ls.c	1996/01/21 03:59:47	2.4
***************
*** 519,534 ****
  	if (a_info == FTS_NS || b_info == FTS_NS)
  		return (namecmp(*a, *b));
  
! 	if (a_info == b_info)
! 		return (sortfcn(*a, *b));
! 
! 	if ((*a)->fts_level == FTS_ROOTLEVEL)
  		if (a_info == FTS_D)
  			return (1);
! 		else if (b_info == FTS_D)
  			return (-1);
! 		else
! 			return (sortfcn(*a, *b));
! 	else
! 		return (sortfcn(*a, *b));
  }
--- 519,530 ----
  	if (a_info == FTS_NS || b_info == FTS_NS)
  		return (namecmp(*a, *b));
  
! 	if (a_info != b_info &&
! 	    (*a)->fts_level == FTS_ROOTLEVEL && !f_listdir) {
  		if (a_info == FTS_D)
  			return (1);
! 		if (b_info == FTS_D)
  			return (-1);
! 	}
! 	return (sortfcn(*a, *b));
  }

>Unformatted:
