]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Read all repository files
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 16 Apr 2021 16:01:10 +0000 (16:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 16 Apr 2021 16:01:10 +0000 (16:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index c60c733ee1b4c0337cbd2b9b0d9b2eab2a58ce1a..1d6fa2745b14b920db685589030b331d0b3e6c70 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <ctype.h>
 #include <errno.h>
+#include <fts.h>
 #include <linux/limits.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -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);