bug-coreutils
[Top][All Lists]
Advanced

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

Patch to ls: avoind auto-mounting.


From: Joao Luis Meloni Assirati
Subject: Patch to ls: avoind auto-mounting.
Date: Fri, 4 Jul 2003 22:34:44 -0300 (BRT)

Hello,

The attached patch to coreutils implements a new command line option
'--nslt' that stands for "never stat link targets". It is to be used in
conjunction with -F and --color to avoid that the targets of links being
listed get stat-ed. This occours in two situations:

1. 'ls --color' tries to determine if a link is broken (orphan)
2. 'ls --color -l' or 'ls -F -l' try to determine which kind of file is
   pointed to by a link.

This behavior is bad when the link points to a location that is mounted by
auto-mounters as, in this case, the location will be mounted.

Typical usage of this new option is by an alias

alias ls='ls -F --color=auto --nslt'

I hope the patch is acceptable. If not, please let me know which
modifications are necessary.

Regards,
Joao Luis M. Assirati.

Index: src/ls.c
===================================================================
RCS file: /cvsroot/coreutils/coreutils/src/ls.c,v
retrieving revision 1.331
diff -u -r1.331 ls.c
--- src/ls.c    17 Jun 2003 18:13:23 -0000      1.331
+++ src/ls.c    5 Jul 2003 01:15:36 -0000
@@ -599,6 +599,11 @@

 static int really_all_files;

+/* Nonzero means that link targets will not be stated
+   which occours when using -F and/or --color  */
+
+static int never_stat_link_targets;
+
 /* A linked list of shell-style globbing patterns.  If a non-argument
    file name matches any of these patterns, it is omitted.
    Controlled by -I.  Multiple -I options accumulate.
@@ -694,6 +699,7 @@
   FORMAT_OPTION,
   FULL_TIME_OPTION,
   INDICATOR_STYLE_OPTION,
+  NEVER_STAT_LINK_TARGETS,
   QUOTING_STYLE_OPTION,
   SHOW_CONTROL_CHARS_OPTION,
   SI_OPTION,
@@ -730,6 +736,7 @@
   {"indicator-style", required_argument, 0, INDICATOR_STYLE_OPTION},
   {"dereference", no_argument, 0, 'L'},
   {"literal", no_argument, 0, 'N'},
+  {"nslt", no_argument, 0, NEVER_STAT_LINK_TARGETS},
   {"quote-name", no_argument, 0, 'Q'},
   {"quoting-style", required_argument, 0, QUOTING_STYLE_OPTION},
   {"recursive", no_argument, 0, 'R'},
@@ -1626,6 +1633,10 @@
                                       indicator_style_types);
          break;

+        case NEVER_STAT_LINK_TARGETS:
+          never_stat_link_targets = 1;
+          break;
+
        case QUOTING_STYLE_OPTION:
          set_quoting_style (NULL,
                             XARGMATCH ("--quoting-style", optarg,
@@ -2418,26 +2429,29 @@
          get_link_name (path, &files[files_index]);
          linkpath = make_link_path (path, files[files_index].linkname);

-         /* Avoid following symbolic links when possible, ie, when
-            they won't be traced and when no indicator is needed. */
-         if (linkpath
-             && (indicator_style != none || check_symlink_color)
-             && stat (linkpath, &linkstats) == 0)
-           {
-             files[files_index].linkok = 1;
-
-             /* Symbolic links to directories that are mentioned on the
-                command line are automatically traced if not being
-                listed as files.  */
-             if (!explicit_arg || format == long_format
-                 || !S_ISDIR (linkstats.st_mode))
-               {
-                 /* Get the linked-to file's mode for the filetype indicator
-                    in long listings.  */
-                 files[files_index].linkmode = linkstats.st_mode;
-                 files[files_index].linkok = 1;
-               }
-           }
+         if (never_stat_link_targets)
+           files[files_index].linkok = 1;
+          else
+           /* Avoid following symbolic links when possible, ie, when
+              they won't be traced and when no indicator is needed. */
+           if (linkpath
+               && (indicator_style != none || check_symlink_color)
+               && stat (linkpath, &linkstats) == 0)
+             {
+               files[files_index].linkok = 1;
+
+               /* Symbolic links to directories that are mentioned on the
+                  command line are automatically traced if not being
+                  listed as files.  */
+               if (!explicit_arg || format == long_format
+                   || !S_ISDIR (linkstats.st_mode))
+                 {
+                   /* Get the linked-to file's mode for the filetype indicator
+                      in long listings.  */
+                   files[files_index].linkmode = linkstats.st_mode;
+                   files[files_index].linkok = 1;
+                 }
+             }
          if (linkpath)
            free (linkpath);
        }
@@ -3791,6 +3805,8 @@
       fputs (_("\
   -f                         do not sort, enable -aU, disable -lst\n\
   -F, --classify             append indicator (one of */=@|) to entries\n\
+      --nslt                 never stat link targets; disable orphan link\n\
+                               detection and target classification\n\
       --format=WORD          across -x, commas -m, horizontal -x, long -l,\n\
                                single-column -1, verbose -l, vertical -C\n\
       --full-time            like -l --time-style=full-iso\n\





reply via email to

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