[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] ls --group-directories-first: symlinks to dirs are dirs too
From: |
Bert Wesarg |
Subject: |
[PATCH] ls --group-directories-first: symlinks to dirs are dirs too |
Date: |
Tue, 12 Feb 2008 14:24:54 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.0 |
With the --group-directories-first option, ls shows directories on top of all
non directory entries, but IMHO symlinks to directories should be handle as
directories as well.
Regards.
Bert
2008-02-12 Bert Wesarg <address@hidden>
ls --group-directories-first: symlinks to dirs are dirs too.
src/ls.c (is_symlink_to_directory): New function.
(DIRFIRST_CHECK): Use it.
---
src/ls.c | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --quilt old/src/ls.c new/src/ls.c
--- old/src/ls.c
+++ new/src/ls.c
@@ -2849,10 +2849,21 @@ static bool
is_directory (const struct fileinfo *f)
{
return f->filetype == directory || f->filetype == arg_directory;
}
+/* Return true if F is a symlink that refers to a directory. */
+static bool
+is_symlink_to_directory (const struct fileinfo *f)
+{
+ return (f->filetype == symbolic_link
+ && f->linkname
+ && f->linkok
+ && f->stat_ok
+ && S_ISDIR (f->linkmode));
+}
+
/* Put the name of the file that FILENAME is a symbolic link to
into the LINKNAME field of `f'. COMMAND_LINE_ARG indicates whether
FILENAME is a command-line argument. */
static void
@@ -2992,12 +3003,14 @@ typedef int (*qsortFunc)(V a, V b);
The do { ... } while(0) makes it possible to use the macro more like
a statement, without violating C89 rules: */
#define DIRFIRST_CHECK(a, b) \
do \
{ \
- bool a_is_dir = is_directory ((struct fileinfo const *) a); \
- bool b_is_dir = is_directory ((struct fileinfo const *) b); \
+ bool a_is_dir = is_directory ((struct fileinfo const *) a) \
+ || is_symlink_to_directory ((struct fileinfo const *) a); \
+ bool b_is_dir = is_directory ((struct fileinfo const *) b) \
+ || is_symlink_to_directory ((struct fileinfo const *) b); \
if (a_is_dir && !b_is_dir) \
return -1; /* a goes before b */ \
if (!a_is_dir && b_is_dir) \
return 1; /* b goes before a */ \
} \
- [PATCH] ls --group-directories-first: symlinks to dirs are dirs too,
Bert Wesarg <=