From a66021bf46fb2a32041a1ffb078761d1b33d17fd Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 17 Oct 2024 06:45:42 +0200 Subject: [PATCH] [FIX] configure.c: Improve recursion rule So far, collect_sources was called recursively when the entry name did not match a pre-defined list. However, this assumption broke with files such as `etc/media/README`, that were not in the list. Therefore, a deterministic way to distinguish files from directories is to rely on the S_ISDIR macro. This avoids the need for a pre-defined list. --- configure.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/configure.c b/configure.c index b0cbee6..6d1f1a7 100644 --- a/configure.c +++ b/configure.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -306,22 +307,29 @@ collect_sources(char *dir, bool head, char *ext) free(na); continue; } - if (!strchr(name, '.') && - strcmp(name, "out") && - strcmp(name, "Makefile")) { - str_array_t *sub; char *d1 = string_cat(dir, "/"); char *d2 = string_cat(d1, name); size_t i; + struct stat sb; - sub = collect_sources(d2, false, ext); - for (i = 0; i < str_array_len(sub); i++) + if (stat(d2, &sb)) { - char *file = str_array_get(sub, i); - str_array_add(ret, file); + fprintf(stderr, "stat(2) %s: %s\n", d2, strerror(errno)); + free(d2); + free(d1); } - str_array_free(sub); + else if (S_ISDIR(sb.st_mode)) + { + str_array_t *sub = collect_sources(d2, false, ext); + for (i = 0; i < str_array_len(sub); i++) + { + char *file = str_array_get(sub, i); + str_array_add(ret, file); + } + str_array_free(sub); + } + free(d2); free(d1); }