]> git.ipfire.org Git - pakfire.git/commitdiff
build: Export all repository configuration into the environment
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Nov 2022 14:01:44 +0000 (14:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Nov 2022 14:01:44 +0000 (14:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 08977a61fb0021f654364d55f0fa2d0423e7aeda..dc3f5e60b4e9802db155799419f38aebbcc330f4 100644 (file)
@@ -100,12 +100,72 @@ static int pakfire_build_has_flag(struct pakfire_build* build, int flag) {
        return build->flags & flag;
 }
 
+static int __pakfire_build_setup_repo(struct pakfire* pakfire,
+               struct pakfire_repo* repo, void* p) {
+       char path[PATH_MAX];
+       FILE* f = NULL;
+       int r;
+
+       struct pakfire_build* build = (struct pakfire_build*)p;
+
+       // Skip processing the installed repository
+       if (pakfire_repo_is_installed_repo(repo))
+               return 0;
+
+       // Skip processing any other internal repositories
+       if (pakfire_repo_is_internal(repo))
+               return 0;
+
+       const char* name = pakfire_repo_get_name(repo);
+
+       DEBUG(pakfire, "Exporting repository configuration for '%s'\n", name);
+
+       // Make path for configuration file
+       r = pakfire_path(build->pakfire, path, PAKFIRE_CONFIG_DIR "/repos/%s.repo", name);
+       if (r) {
+               ERROR(pakfire, "Could not make repository configuration path for %s: %m\n", name);
+               goto ERROR;
+       }
+
+       // Open the repository configuration
+       f = fopen(path, "w");
+       if (!f) {
+               ERROR(pakfire, "Could not open %s for writing: %m\n", path);
+               goto ERROR;
+       }
+
+       // Write repository configuration
+       r = pakfire_repo_write_config(repo, f);
+       if (r) {
+               ERROR(pakfire, "Could not write repository configuration for %s: %m\n", name);
+               goto ERROR;
+       }
+
+       // Bind-mount any local repositories
+       if (pakfire_repo_is_local(repo)) {
+               const char* _path = pakfire_repo_get_path(repo);
+
+               // Bind-mount the repository data read-only
+               r = pakfire_jail_bind(build->jail, _path, _path, MS_RDONLY);
+               if (r) {
+                       ERROR(pakfire, "Could not bind-mount the repository at %s: %m\n", _path);
+                       goto ERROR;
+               }
+       }
+
+ERROR:
+       if (f)
+               fclose(f);
+
+       return r;
+}
+
 /*
        This function enables the local repository so that it can be accessed by
        a pakfire instance running inside the chroot.
 */
 static int pakfire_build_enable_repos(struct pakfire_build* build) {
-       return 0;
+       return pakfire_repo_walk(build->pakfire, __pakfire_build_setup_repo, build);
 }
 
 /*