Date: Wed, 26 Dec 2001 01:59:26 -0800 (PST) From: mikem <mike_makonnen@yahoo.com> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/33187: [PATCH] /bin/ls -dF adds trailing slash regardless of whether there is already one there Message-ID: <200112260959.fBQ9xQV00996@blackbox.pacbell.net>
next in thread | raw e-mail | index | archive | help
>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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200112260959.fBQ9xQV00996>
