From 86eb680bbfd096ab1a2664e36f80f4bea55e18cf Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 9 Jul 2020 08:52:24 +0100 Subject: ls: treat hidden files as if their names begin with a dot On Unix 'ls' treats filenames starting with a dot as hidden and only displays them if the '-a' or '-A' option is given. Extend similar treatment to files with the Windows hidden flag. --- coreutils/ls.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/coreutils/ls.c b/coreutils/ls.c index 3eff5a949..fb082f1f3 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -316,6 +316,9 @@ struct dnode { int dn_rdev_min; // dev_t dn_dev; // blksize_t dn_blksize; +#if ENABLE_PLATFORM_MINGW32 + DWORD dn_attr; +#endif }; struct globals { @@ -742,6 +745,9 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f /* cur->dstat = statbuf: */ cur->dn_mode = statbuf.st_mode ; +#if ENABLE_PLATFORM_MINGW32 + cur->dn_attr = statbuf.st_attr ; +#endif cur->dn_size = statbuf.st_size ; #if ENABLE_FEATURE_LS_TIMESTAMPS || ENABLE_FEATURE_LS_SORTFILES cur->dn_time = statbuf.st_mtime ; @@ -953,7 +959,13 @@ static struct dnode **scan_one_dir(const char *path, unsigned *nfiles_p) } fullname = concat_path_file(path, entry->d_name); cur = my_stat(fullname, bb_basename(fullname), 0); +#if !ENABLE_PLATFORM_MINGW32 if (!cur) { +#else + if (!cur || ((cur->dn_attr & FILE_ATTRIBUTE_HIDDEN) && + !(option_mask32 & (OPT_a|OPT_A)))) { + /* skip invalid or hidden files */ +#endif free(fullname); continue; } -- cgit v1.2.3-55-g6feb