diff options
author | Ron Yorston <rmy@pobox.com> | 2023-06-06 09:51:05 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-06-06 09:51:05 +0100 |
commit | 8788a6b7a7bc0a6b8800b5f5334c485f4aed6f09 (patch) | |
tree | 5a98cdb2370eda23de58b43b36bcd104e31ec35c | |
parent | 6fcf8ade94f6cb05a57562abb6a5491a39146682 (diff) | |
download | busybox-w32-8788a6b7a7bc0a6b8800b5f5334c485f4aed6f09.tar.gz busybox-w32-8788a6b7a7bc0a6b8800b5f5334c485f4aed6f09.tar.bz2 busybox-w32-8788a6b7a7bc0a6b8800b5f5334c485f4aed6f09.zip |
ls: check whether link is hidden
When using 'ls -L' to list the target of a symlink (or equivalent)
we must first check whether the link itself is hidden and thus
subject to special treatment by the '-a' or '-A' options.
Adds 80 bytes.
(GitHub issue #331)
-rw-r--r-- | coreutils/ls.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index d15588a13..8589c854e 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -948,6 +948,9 @@ static struct dnode **scan_one_dir(const char *path, unsigned *nfiles_p) | |||
948 | struct dirent *entry; | 948 | struct dirent *entry; |
949 | DIR *dir; | 949 | DIR *dir; |
950 | unsigned i, nfiles; | 950 | unsigned i, nfiles; |
951 | #if ENABLE_PLATFORM_MINGW32 | ||
952 | struct stat statbuf; | ||
953 | #endif | ||
951 | 954 | ||
952 | *nfiles_p = 0; | 955 | *nfiles_p = 0; |
953 | dir = warn_opendir(path); | 956 | dir = warn_opendir(path); |
@@ -976,6 +979,20 @@ static struct dnode **scan_one_dir(const char *path, unsigned *nfiles_p) | |||
976 | else | 979 | else |
977 | #endif | 980 | #endif |
978 | fullname = concat_path_file(path, entry->d_name); | 981 | fullname = concat_path_file(path, entry->d_name); |
982 | #if ENABLE_PLATFORM_MINGW32 | ||
983 | /* When showing link targets we must first check the | ||
984 | * attributes of the link itself to see if it's hidden. */ | ||
985 | if ((option_mask32 & OPT_L) && !lstat(fullname, &statbuf)) { | ||
986 | if (((statbuf.st_attr & FILE_ATTRIBUTE_HIDDEN) && | ||
987 | !(option_mask32 & (OPT_a|OPT_A))) || | ||
988 | (((statbuf.st_attr & HIDSYS) == HIDSYS) && | ||
989 | MAX(G.a_count, G.A_count) > 1) | ||
990 | ) { | ||
991 | free(fullname); | ||
992 | continue; | ||
993 | } | ||
994 | } | ||
995 | #endif | ||
979 | cur = my_stat(fullname, bb_basename(fullname), 0); | 996 | cur = my_stat(fullname, bb_basename(fullname), 0); |
980 | #if !ENABLE_PLATFORM_MINGW32 | 997 | #if !ENABLE_PLATFORM_MINGW32 |
981 | if (!cur) { | 998 | if (!cur) { |