Subject: Re: bug#9637: ls appends an indicator even if one is already present (--indicator-style=classify)

From: Eric Blake <[email-masked]>
Date: Fri, 30 Sep 2011 11:35:56 -0600

tag 9637 notabug
thanks

On 09/30/2011 04:42 AM, Philip Ganchev wrote:
> "Ls --indicator-style=classify" always appends a slash to the names of
> directories. For example:
>
> ls -d */
>
> dir1// dir2//

Correct, and this behavior is required by POSIX:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html

-F
     Do not follow symbolic links named as operands unless the -H or -L 
options are specified. Write a <slash> ( '/' ) immediately after each 
pathname that is a directory, an <asterisk> ( '*' ) after each that is 
executable, a <vertical-line> ( '|' ) after each that is a FIFO, and an 
at-sign ( '@' ) after each that is a symbolic link. For other file 
types, other symbols may be written.

-p
     Write a <slash> ( '/' ) after each filename if that file is a 
directory.

Neither of those options mention that the slash may be omitted if the 
user's command-line option already included a slash.  We'd have to take 
it up with the POSIX folks to get that changed, before we could change 
coreutils' behavior.

In particular, we have to be careful that:

ls -p / // ///

does not make the results ambiguous.  That is, while / and /// are 
necessarily the same directory, / and // can differ, so if we omit 
adding an extra slash because one is already present, then we risk 
confusing scripts that depend on stripping the trailing slash added by 
-p to convert the traditional output back into the proper directory names.

>
> Ls should check if an indicator is already present after the end of
> the file name, and append it only if it is not.

It's worth requesting that as an enhancement to POSIX, but I don't see 
coreutils making any changes here unless a POSIX change is made first to 
permit such an output optimization.

-- 
Eric Blake   [email-masked]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org