Re: more ls changes: stat-failed

2006-07-26 Thread Jim Meyering
Paul Eggert [EMAIL PROTECTED] wrote:

 Jim Meyering [EMAIL PROTECTED] 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.

I do like it.  Thanks for doing that.
But please put the name change (s/stat_failed/stat_ok)
in a separate delta.


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: more ls changes: stat-failed

2006-07-26 Thread Jim Meyering
Paul Eggert [EMAIL PROTECTED] wrote:

 Jim Meyering [EMAIL PROTECTED] 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.c26 Jul 2006 13:47:41 -  1.433
+++ src/ls.c26 Jul 2006 13:48:35 -
@@ -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.c26 Jul 2006 13:47:41 -  1.433
+++ src/ls.c26 Jul 2006 13:51:03 -
@@ -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;
}
 }
 


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: more ls changes: stat-failed

2006-07-25 Thread Paul Eggert
Jim Meyering [EMAIL PROTECTED] 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.

2006-07-25  Paul Eggert  [EMAIL PROTECTED]

* src/ls.c (DT_INIT): Remove.  All uses removed.
(enum filetype): Use an ordinary enum rather than trying to keep
the values in sync with DT_FIFO etc.  That way, we don't have
to make special assumptions about them.  All uses changed.
(whiteout): New constant member of enum filetype.
(filetype_letter): New constant, for use with enum filetype.
(struct fileinfo): Rename stat_failed to stat_ok, since stat
might not necessarily have failed if this value is (now) false.
All uses changed.
(format_user, format_group, print_name_with_quoting): Likewise.
(print_color_indicator): Likewise.
(print_dir): Add case for DT_WHT.
(gobble_file): If stat fails, don't discard information from
readdir; instead, preserve it so it can be printed.
(print_long_format): Fall back on readdir result if stat info
is not available.  Use ? to denote each unknown mode char,
instead of an overall ?, since we now know some of the mode
typically.
[... changelog not finished, alas ]

Index: doc/coreutils.texi
===
RCS file: /fetish/cu/doc/coreutils.texi,v
retrieving revision 1.341
diff -p -u -r1.341 coreutils.texi
--- doc/coreutils.texi  23 Jul 2006 01:26:56 -  1.341
+++ doc/coreutils.texi  25 Jul 2006 23:36:28 -
@@ -5795,7 +5795,8 @@ uniquely identifies each file within a p
 In addition to the name of each file, print the file type, file mode bits,
 number of hard links, owner name, group name, size, and
 timestamp (@pxref{Formatting file timestamps}), normally
-the modification time.
+the modification time.  Print question marks for information that
+cannot be determined.
 
 Normally the size is printed as a byte count without punctuation, but
 this can be overridden (@pxref{Block size}).  For example, @option{-h}
@@ -5852,7 +5853,7 @@ socket
 @c @item w
 @c whiteout (4.4BSD; not implemented)
 @item ?
-some other file type
+unknown file type
 @end table
 
 @cindex permissions, output by @command{ls}
Index: src/ls.c
===
RCS file: /fetish/cu/src/ls.c,v
retrieving revision 1.430
diff -p -u -r1.430 ls.c
--- src/ls.c25 Jul 2006 16:35:59 -  1.430
+++ src/ls.c25 Jul 2006 23:36:29 -
@@ -142,37 +142,43 @@ int wcwidth ();
Subtracting doesn't always work, due to overflow.  */
 #define longdiff(a, b) ((a)  (b) ? -1 : (a)  (b))
 
-#if HAVE_STRUCT_DIRENT_D_TYPE  defined DTTOIF
-# define DT_INIT(Val) = Val
-#else
-# define DT_INIT(Val) /* empty */
-#endif
-
 #if ! HAVE_STRUCT_STAT_ST_AUTHOR
 # define st_author st_uid
 #endif
 
 enum filetype
   {
-unknown DT_INIT (DT_UNKNOWN),
-fifo DT_INIT (DT_FIFO),
-chardev DT_INIT (DT_CHR),
-directory DT_INIT (DT_DIR),
-blockdev DT_INIT (DT_BLK),
-normal DT_INIT (DT_REG),
-symbolic_link DT_INIT (DT_LNK),
-sock DT_INIT (DT_SOCK),
-arg_directory DT_INIT (2 * (DT_UNKNOWN | DT_FIFO | DT_CHR | DT_DIR | DT_BLK
-   | DT_REG | DT_LNK | DT_SOCK))
+unknown,
+fifo,
+chardev,
+directory,
+blockdev,
+normal,
+symbolic_link,
+sock,
+whiteout,
+arg_directory
   };
 
+/* Display letters and indicators for each filetype.
+   Keep these in sync with enum filetype.  */
+
+static char const filetype_letter[] = ?pcdb-lswd;
+
+#define FILETYPE_INDICATORS\
+  {\
+C_ORPHAN, C_FIFO, C_CHR, C_DIR, C_BLK, C_FILE, \
+C_LINK, C_SOCK, C_FILE, C_DIR  \
+  }
+
+
 struct fileinfo
   {
 /* The file name.  */
 char *name;
 
 struct stat stat;
-bool stat_failed;
+bool stat_ok;
 
 /* For symbolic link, name of the file linked to, otherwise zero.  */
 char *linkname;
@@ -228,7 +234,7 @@ static uintmax_t gobble_file (char const
  ino_t inode, bool command_line_arg,
  char const *dirname);
 static void print_color_indicator (const char *name, mode_t mode, int linkok,
-  bool stat_failed);
+