mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 13:45:10 +00:00
[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.
This commit is contained in:
parent
ecbc211003
commit
a66021bf46
1 changed files with 17 additions and 9 deletions
18
configure.c
18
configure.c
|
|
@ -11,6 +11,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <stdbool.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
|
@ -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);
|
||||
if (stat(d2, &sb))
|
||||
{
|
||||
fprintf(stderr, "stat(2) %s: %s\n", d2, strerror(errno));
|
||||
free(d2);
|
||||
free(d1);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue