From: Michael Tremer Date: Fri, 16 Apr 2021 16:01:10 +0000 (+0000) Subject: pakfire: Read all repository files X-Git-Tag: 0.9.28~1285^2~342 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d1e84dfb052bd119e92e9fda293435eee876928;p=pakfire.git pakfire: Read all repository files Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index c60c733ee..1d6fa2745 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -399,6 +400,54 @@ static int pakfire_safety_checks(Pakfire pakfire) { return 0; } +static int pakfire_read_repo_config(Pakfire pakfire) { + char* path = pakfire_make_path(pakfire, PAKFIRE_CONFIG_PATH "/repos"); + if (!path) + return ENOMEM; + + int r = 0; + char* paths[2] = { + path, NULL, + }; + + FTS* d = fts_open(paths, FTS_NOCHDIR|FTS_NOSTAT, NULL); + if (!d) + goto ERROR; + + for (;;) { + FTSENT* fent = fts_read(d); + if (!fent) + break; + + // Only handle files + if (fent->fts_info & FTS_F) { + // Skip everything that doesn't end in .repo + if (!pakfire_string_endswith(fent->fts_name, ".repo")) + continue; + + DEBUG(pakfire, "Reading %s\n", fent->fts_path); + + FILE* f = fopen(fent->fts_path, "r"); + if (!f) + goto ERROR; + + // Parse the configuration file + r = pakfire_config_read(pakfire->config, f); + fclose(f); + + if (r) + goto ERROR; + } + } + +ERROR: + if (d) + fts_close(d); + free(path); + + return r; +} + static int pakfire_config_import_distro(Pakfire pakfire) { // Nothing to do if there is no distro section if (!pakfire_config_has_section(pakfire->config, "distro")) @@ -481,6 +530,11 @@ static int pakfire_read_config(Pakfire pakfire, const char* path) { if (r) goto ERROR; + // Read repository configuration + r = pakfire_read_repo_config(pakfire); + if (r) + goto ERROR; + ERROR: fclose(f);