bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: more ls changes: stat-failed


From: Jim Meyering
Subject: Re: more ls changes: stat-failed
Date: Wed, 26 Jul 2006 16:10:49 +0200

Paul Eggert <address@hidden> wrote:

> Jim Meyering <address@hidden> writes:
>
>>   ?--------- ? ?    ?    ?            ? cwd
>
> How about outputting something like this instead?
>
>     d????????? ? ?    ?    ?            ? cwd
>
> The file type is typically known, so it can be listed as "d" instead
> of "?".  Also, this example doesn't show it, but the inode number is
> also known typically, so it shouldn't be listed as "?".
>
> Conversely, the file mode bits are not known, so they should be listed
> as "?" rather than as the (misleading) "-".
>
> I hacked on a patch along these lines but did not have time to finish
> it; it fails the tests due to problems with file name colors.  However,
> if you like the idea I can work on cleaning this up.

Thanks,
I've gone ahead and checked that in (in two separate deltas).

FYI, the following patch solves the problem with the failing test,
but I'm checking in a slightly larger one, below.

Also, regarding your coreutils.texi changes, I've omitted this part

    -some other file type
    +unknown file type

since the other types may well be known (see lib/file-type.c),
just not handled by ls's color-classification code.

Index: src/ls.c
===================================================================
RCS file: /fetish/cu/src/ls.c,v
retrieving revision 1.433
diff -u -p -r1.433 ls.c
--- src/ls.c    26 Jul 2006 13:47:41 -0000      1.433
+++ src/ls.c    26 Jul 2006 13:48:35 -0000
@@ -3871,8 +3871,6 @@ print_color_indicator (const char *name,
        type = C_CHR;
       else if (S_ISDOOR (mode))
        type = C_DOOR;
-      else
-       type = C_ORPHAN;
 
       if (type == C_FILE)
        {

Here's what I'm checking in:

        * src/ls.c (print_color_indicator): Test for S_IFREG first, rather
        than having the code test for all of the other types first.
        Hoist the set-uid/gid-testing code "up" into this new block.
        Classify any other type of file (e.g., S_TYPEISSHM, etc.) as
        C_ORPHAN, not as C_FILE.

Index: src/ls.c
===================================================================
RCS file: /fetish/cu/src/ls.c,v
retrieving revision 1.433
diff -u -p -r1.433 ls.c
--- src/ls.c    26 Jul 2006 13:47:41 -0000      1.433
+++ src/ls.c    26 Jul 2006 13:51:03 -0000
@@ -3832,7 +3832,7 @@ static void
 print_color_indicator (const char *name, mode_t mode, int linkok,
                       bool stat_ok, enum filetype filetype)
 {
-  int type = C_FILE;
+  int type;
   struct color_ext_type *ext;  /* Color extension */
   size_t len;                  /* Length of name */
 
@@ -3847,7 +3847,17 @@ print_color_indicator (const char *name,
     }
   else
     {
-      if (S_ISDIR (mode))
+      if (S_ISREG (mode))
+       {
+         type = C_FILE;
+         if ((mode & S_ISUID) != 0)
+           type = C_SETUID;
+         else if ((mode & S_ISGID) != 0)
+           type = C_SETGID;
+         else if ((mode & S_IXUGO) != 0)
+           type = C_EXEC;
+       }
+      else if (S_ISDIR (mode))
        {
          if ((mode & S_ISVTX) && (mode & S_IWOTH))
            type = C_STICKY_OTHER_WRITABLE;
@@ -3872,16 +3882,9 @@ print_color_indicator (const char *name,
       else if (S_ISDOOR (mode))
        type = C_DOOR;
       else
-       type = C_ORPHAN;
-
-      if (type == C_FILE)
        {
-         if ((mode & S_ISUID) != 0)
-           type = C_SETUID;
-         else if ((mode & S_ISGID) != 0)
-           type = C_SETGID;
-         else if ((mode & S_IXUGO) != 0)
-           type = C_EXEC;
+         /* Classify a file of some other type as C_ORPHAN.  */
+         type = C_ORPHAN;
        }
     }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]