[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch 4/4] treat symlinks in --group-dir as type pointed to
From: |
Jan Engelhardt |
Subject: |
[patch 4/4] treat symlinks in --group-dir as type pointed to |
Date: |
Sat, 21 Jun 2008 12:49:56 +0200 (CEST) |
User-agent: |
Alpine 1.10 (LNX 962 2008-03-14) |
If the symlink points to a directory, take it as one when sorting
by directory is turned on.
---
src/ls.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
Index: coreutils-6.11/src/ls.c
===================================================================
--- coreutils-6.11.orig/src/ls.c
+++ coreutils-6.11/src/ls.c
@@ -3004,12 +3004,16 @@ typedef int (*qsortFunc)(V a, V b);
#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); \
- 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 */ \
+ const struct fileinfo *fa = a, *fb = b; \
+ enum filetype ta = fa->filetype, tb = fb->filetype; \
+ if (fa->filetype == symbolic_link && fa->linkname != NULL) \
+ ta = S_ISDIR(fa->linkmode) ? directory : normal; \
+ if (fb->filetype == symbolic_link && fb->linkname != NULL) \
+ tb = S_ISDIR(fb->linkmode) ? directory : normal; \
+ if (ta == directory && tb != directory) \
+ return -1; \
+ if (ta != directory && tb == directory) \
+ return 1; \
} \
while (0)