From b7c522765e4926024aea82e8b3b2372d210f4ba3 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 1 Nov 2022 14:01:44 +0000 Subject: [PATCH] build: Export all repository configuration into the environment Signed-off-by: Michael Tremer --- src/libpakfire/build.c | 62 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 08977a61f..dc3f5e60b 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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); } /* -- 2.39.5