From: Michael Tremer Date: Wed, 22 Sep 2021 10:15:42 +0000 (+0000) Subject: build: Automatically create the local repository X-Git-Tag: 0.9.28~939 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ccac5e5136a879384fbf0d397b37b99299be1a6;p=pakfire.git build: Automatically create the local repository Signed-off-by: Michael Tremer --- diff --git a/contrib/config/distros/ipfire3.conf b/contrib/config/distros/ipfire3.conf index ae4cae262..0caefecb3 100644 --- a/contrib/config/distros/ipfire3.conf +++ b/contrib/config/distros/ipfire3.conf @@ -35,8 +35,3 @@ description = IPFire 3 - Unstable Repository baseurl = https://pakfire.ipfire.org/repositories/ipfire3/unstable/%{arch} mirrors = https://pakfire.ipfire.org/distro/ipfire3/repo/unstable/mirrorlist?arch=%{arch} priority = 300 - -[repo:@local] -description = IPFire 3 locally built packages -baseurl = file:///var/lib/pakfire/local/ipfire3 -priority = 1000 diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index e5dfd6825..998eb86a1 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -743,7 +743,7 @@ PAKFIRE_EXPORT int pakfire_build(struct pakfire* pakfire, const char* path, // The default target is the local repository path if (!target) { - struct pakfire_repo* repo = pakfire_get_repo(pakfire, "@local"); + struct pakfire_repo* repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL); if (repo) { target = pakfire_repo_get_path(repo); pakfire_repo_unref(repo); @@ -814,9 +814,9 @@ int pakfire_build_clean(struct pakfire* pakfire, int flags) { int r = 0; // Fetch local repository - local = pakfire_get_repo(pakfire, "@local"); + local = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL); if (!local) { - ERROR(pakfire, "Could not find local repository: %m\n"); + ERROR(pakfire, "Could not find repository %s: %m\n", PAKFIRE_REPO_LOCAL); goto ERROR; } diff --git a/src/libpakfire/include/pakfire/repo.h b/src/libpakfire/include/pakfire/repo.h index 37c79ab62..9317dec0b 100644 --- a/src/libpakfire/include/pakfire/repo.h +++ b/src/libpakfire/include/pakfire/repo.h @@ -101,6 +101,10 @@ int pakfire_repo_compose(struct pakfire* pakfire, const char* path, int flags, #include #include +#define PAKFIRE_REPO_LOCAL "local" +#define PAKFIRE_REPO_LOCAL_PATH "file://" PAKFIRE_PRIVATE_DIR "/local/%{distro}/%{version}" +#define PAKFIRE_REPO_LOCAL_PRIORITY 1000 + int pakfire_repo_import(struct pakfire* pakfire, struct pakfire_config* config); const char* pakfire_repo_get_path(struct pakfire_repo* repo); diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 3f412248e..69f1a6e6a 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -219,6 +219,32 @@ int pakfire_repo_import(struct pakfire* pakfire, struct pakfire_config* config) pakfire_repo_unref(repo); } + // Add local repository (in build mode) + if (pakfire_has_flag(pakfire, PAKFIRE_FLAGS_BUILD)) { + // Does this repository exist already? + repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL); + + // Create it if it doesn't exist, yet + if (!repo) { + r = pakfire_repo_create(&repo, pakfire, PAKFIRE_REPO_LOCAL); + if (r) { + ERROR(pakfire, "Could not create repository %s: %m\n", PAKFIRE_REPO_LOCAL); + goto ERROR; + } + + // Set description + pakfire_repo_set_description(repo, _("Locally built packages")); + + // Set path + pakfire_repo_set_baseurl(repo, PAKFIRE_REPO_LOCAL_PATH); + + // Set priority + pakfire_repo_set_priority(repo, PAKFIRE_REPO_LOCAL_PRIORITY); + + pakfire_repo_unref(repo); + } + } + ERROR: for (char** section = sections; *section; section++) free(*section); @@ -658,15 +684,14 @@ static char* pakfire_repo_url_replace(struct pakfire_repo* repo, const char* url if (!url) return NULL; - const char* arch = pakfire_get_arch(repo->pakfire); - const char* name = pakfire_repo_get_name(repo); - const struct replacement { const char* pattern; const char* replacement; } replacements[] = { - { "%{name}", name }, - { "%{arch}", arch }, + { "%{name}", pakfire_repo_get_name(repo) }, + { "%{arch}", pakfire_get_arch(repo->pakfire) }, + { "%{distro}", pakfire_get_distro_id(repo->pakfire) }, + { "%{version}", pakfire_get_distro_version_id(repo->pakfire) }, { NULL, NULL }, };