From owner-freebsd-bugs Wed Dec 26 1:50: 8 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 1A88D37B416 for ; Wed, 26 Dec 2001 01:50:01 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id fBQ9o1i20415; Wed, 26 Dec 2001 01:50:01 -0800 (PST) (envelope-from gnats) Received: from mta7.pltn13.pbi.net (mta7.pltn13.pbi.net [64.164.98.8]) by hub.freebsd.org (Postfix) with ESMTP id 0D71537B416 for ; Wed, 26 Dec 2001 01:47:58 -0800 (PST) Received: from blackbox.pacbell.net ([64.172.24.78]) by mta7.pltn13.pbi.net (iPlanet Messaging Server 5.1 (built May 7 2001)) with ESMTP id <0GOY008QP37XZ2@mta7.pltn13.pbi.net> for FreeBSD-gnats-submit@freebsd.org; Wed, 26 Dec 2001 01:47:57 -0800 (PST) Received: (from mikem@localhost) by blackbox.pacbell.net (8.11.6/8.11.6) id fBQ9xQV00996; Wed, 26 Dec 2001 01:59:26 -0800 (PST envelope-from mikem) Message-Id: <200112260959.fBQ9xQV00996@blackbox.pacbell.net> Date: Wed, 26 Dec 2001 01:59:26 -0800 (PST) From: mikem Reply-To: mikem To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: bin/33187: [PATCH] /bin/ls -dF adds trailing slash regardless of whether there is already one there Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 33187 >Category: bin >Synopsis: [PATCH] /bin/ls -dF adds trailing slash regardless of whether there is already one there >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Dec 26 01:50:01 PST 2001 >Closed-Date: >Last-Modified: >Originator: mikem >Release: FreeBSD 5.0-CURRENT i386 >Organization: >Environment: System: FreeBSD blackbox.pacbell.net 5.0-CURRENT FreeBSD 5.0-CURRENT #1: Fri Dec 21 01:57:15 PST 2001 mikem@blackbox.pacbell.net:/FreeBSD/obj.current/FreeBSD/current/src/sys/BLACKBOX i386 >Description: If a user specifies a directory with a trailing forward slash to ls -dF, ls adds another trailing '/'. If you specify /usr/, the output is /usr//. Among other things, this behaviour will screw up any scripts or programs that chop trailing forward slashes. >How-To-Repeat: % ls -dF /usr/ or % ls -dF /usr/*/ >Fix: I've included a patch. It was necessary to change the arguments that print.c:printtype() takes. Also, while fixing this bug it introduces another subtle bug: if the -G switch is enabled, the trailing backslash will also be colorized. for example: % ls -dFG /usr/ /usr will output: /usr/ (where the '/' will be colorized) /usr/ (where the '/' will *not* be colorized A simple solution would be to colorize not just the file/dir names, but also the trailing type specifiers. While it's not good practice to introduce one bug just to fix another, in this case I think the tradeoff is ok. One bug merely makes ls output a little less pretty, while the other one can screw up other programs and scripts. In any case, here's the patch. Do what you will with it. --- /usr/src/bin/ls/print.c Tue Nov 27 06:30:05 2001 +++ print.c Wed Dec 26 00:49:54 2001 @@ -69,7 +69,7 @@ static int printaname __P((FTSENT *, u_long, u_long)); static void printlink __P((FTSENT *)); static void printtime __P((time_t)); -static int printtype __P((u_int)); +static int printtype __P((u_int, const char*, u_int len)); #ifdef COLORLS static void endcolor __P((int)); static int colortype __P((mode_t)); @@ -190,7 +190,7 @@ endcolor(0); #endif if (f_type) - (void)printtype(sp->st_mode); + (void)printtype(sp->st_mode, p->fts_name, p->fts_namelen); if (S_ISLNK(sp->st_mode)) printlink(p); (void)putchar('\n'); @@ -301,7 +301,7 @@ endcolor(0); #endif if (f_type) - chcnt += printtype(sp->st_mode); + chcnt += printtype(sp->st_mode, p->fts_name, p->fts_namelen); return (chcnt); } @@ -334,12 +334,14 @@ } static int -printtype(mode) - u_int mode; +printtype(mode, name, len) + const char* name; + u_int mode, len; { switch (mode & S_IFMT) { case S_IFDIR: - (void)putchar('/'); + if (name[len - 1] != '/') + (void)putchar('/'); return (1); case S_IFIFO: (void)putchar('|'); >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message