From 1a88782fd33db4ad3531b63c9fb744c64282fee2 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 23 Jan 2023 10:40:57 +0000 Subject: win32: only count subdirectories if necessary Commit 7fb95a2a5 (win32: try to get link count for directories) allowed stat(2) to report accurate values of st_nlink for directories. There are only a couple of places in busybox-w32 where these values are required. Disable counting of subdirectories by default and only enable it when necessary. Microsoft kindly provide directories to test edge cases like this: C:/Windows/WinSxS (contains many subdirectories) C:/Windows/WinSxS/Manifests (contains many files) Adds 84-112 bytes. --- coreutils/ls.c | 6 ++++++ coreutils/stat.c | 4 ++++ 2 files changed, 10 insertions(+) (limited to 'coreutils') diff --git a/coreutils/ls.c b/coreutils/ls.c index d8cfe27d3..3c659294c 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -1241,6 +1241,12 @@ int ls_main(int argc UNUSED_PARAM, char **argv) option_mask32 |= OPT_dirs_first; } +#if ENABLE_FEATURE_EXTRA_FILE_DATA + /* Enable accurate link counts for directories */ + if (opt & OPT_l) + count_subdirs(NULL); +#endif + argv += optind; if (!argv[0]) *--argv = (char*)"."; diff --git a/coreutils/stat.c b/coreutils/stat.c index 940ade89a..dc20c2356 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c @@ -784,6 +784,10 @@ int stat_main(int argc UNUSED_PARAM, char **argv) if (opts & OPT_SELINUX) { selinux_or_die(); } +#endif +#if ENABLE_FEATURE_EXTRA_FILE_DATA + /* Enable accurate link counts for directories */ + count_subdirs(NULL); #endif ok = 1; argv += optind; -- cgit v1.2.3-55-g6feb