]> git.ipfire.org Git - pakfire.git/commitdiff
build: Move creating the local repository into Pakfire
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 15:54:04 +0000 (15:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 15:54:04 +0000 (15:54 +0000)
Pakfire is kind of the thing that should do the setup. That way, we have
it all in one place instead of two places of setup.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/build.c
src/pakfire/pakfire.c
src/pakfire/pakfire.h

index d45a0453a1e6933f847ca4f00ef7060e06f438c5..527bd3186b2071571edd09f9a5107f691cef90f0 100644 (file)
@@ -93,9 +93,6 @@ struct pakfire_build {
        // The build repository
        struct pakfire_repo* repo;
 
-       // The local repository
-       struct pakfire_repo* local;
-
        // Buildroot
        char buildroot[PATH_MAX];
 
@@ -1669,10 +1666,6 @@ static void pakfire_build_free(struct pakfire_build* build) {
                pakfire_repo_unref(build->repo);
        }
 
-       // Free the local repository
-       if (build->local)
-               pakfire_repo_unref(build->local);
-
        if (build->jail)
                pakfire_jail_unref(build->jail);
        if (build->env)
@@ -1906,91 +1899,11 @@ static int pakfire_build_setup_ccache(struct pakfire_build* build) {
        return 0;
 }
 
-static int pakfire_build_setup_local_repo(struct pakfire_build* self) {
-       char path[PATH_MAX];
-       char url[PATH_MAX];
-       int r;
-
-       // Fetch distro ID
-       const char* distro_id  = pakfire_get_distro_id(self->pakfire);
-       if (!distro_id) {
-               ERROR(self->ctx, "Could not fetch the distro ID\n");
-               return -EINVAL;
-       }
-
-       // Fetch the distro version ID
-       const char* version_id = pakfire_get_distro_version_id(self->pakfire);
-       if (!version_id) {
-               ERROR(self->ctx, "Could not fetch the distro version ID\n");
-               return -EINVAL;
-       }
-
-       // Make the repository path
-       r = pakfire_string_format(path,
-                       "~/.local/share/%s/%s/%s", PACKAGE_NAME, distro_id, version_id);
-       if (r < 0) {
-               ERROR(self->ctx, "Could not compose the local repository path: %s\n", strerror(-r));
-               return r;
-       }
-
-       // Expand the path
-       r = pakfire_path_expand(path, path);
-       if (r < 0) {
-               ERROR(self->ctx, "Could not expand the local repository path: %s\n", strerror(-r));
-               return r;
-       }
-
-       // Create the path
-       r = pakfire_mkdir(path, 0700);
-       if (r < 0) {
-               ERROR(self->ctx, "Could not create the local repository at %s: %s\n",
-                       path, strerror(-r));
-               return r;
-       }
-
-       // Create a new repository
-       r = pakfire_repo_create(&self->local, self->pakfire, PAKFIRE_REPO_LOCAL);
-       if (r < 0) {
-               ERROR(self->ctx, "Could not create local repository: %s\n", strerror(-r));
-               return r;
-       }
-
-       // Set description
-       r = pakfire_repo_set_description(self->local, _("Locally Built Packages"));
-       if (r < 0) {
-               ERROR(self->ctx, "Could not set local repository description: %s\n", strerror(-r));
-               return r;
-       }
-
-       // Compose the URL
-       r = pakfire_string_format(url, "file://%s", path);
-       if (r < 0) {
-               ERROR(self->ctx, "Could not compose the local repository URL: %s\n", strerror(-r));
-               return r;
-       }
-
-       // Set the URL
-       r = pakfire_repo_set_baseurl(self->local, url);
-       if (r < 0) {
-               ERROR(self->ctx, "Could not set local repository URL: %s\n", strerror(-r));
-               return r;
-       }
-
-       return 0;
-}
-
 static int pakfire_build_setup_repo(struct pakfire_build* build) {
        char path[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-build-repo.XXXXXX";
        char url[PATH_MAX];
        int r;
 
-       // Create a local repository for local builds
-       if (pakfire_build_has_flag(build, PAKFIRE_BUILD_LOCAL)) {
-               r = pakfire_build_setup_local_repo(build);
-               if (r < 0)
-                       return r;
-       }
-
        // Create a new repository
        r = pakfire_repo_create(&build->repo, build->pakfire, PAKFIRE_REPO_RESULT);
        if (r) {
@@ -2035,6 +1948,10 @@ static int pakfire_build_setup_pakfire(
        int flags = PAKFIRE_FLAGS_BUILD;
        int r;
 
+       // Is this a local build?
+       if (build->flags & PAKFIRE_BUILD_LOCAL)
+               flags |= PAKFIRE_FLAGS_BUILD_LOCAL;
+
        // Enable snapshot?
        if (build->flags & PAKFIRE_BUILD_ENABLE_SNAPSHOT)
                flags |= PAKFIRE_USE_SNAPSHOT;
index c13ee4fd7b607a487fca08ba308d8f6930da7298..21bbc2e111209022c5e2ba51352ddedbc977155e 100644 (file)
@@ -50,6 +50,7 @@
 #include <pakfire/deps.h>
 #include <pakfire/dist.h>
 #include <pakfire/logging.h>
+#include <pakfire/i18n.h>
 #include <pakfire/mount.h>
 #include <pakfire/os.h>
 #include <pakfire/package.h>
@@ -398,6 +399,17 @@ static void pakfire_free(struct pakfire* pakfire) {
                pakfire_repo_unref(repo);
        }
 
+       // Write back the local repository
+       repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL);
+       if (repo) {
+               // Write back the local repository metadata
+               r = pakfire_repo_write_metadata(repo, NULL);
+               if (r)
+                       ERROR(pakfire->ctx, "Could not write the local repository: %s. Ignoring.\n", strerror(-r));
+
+               pakfire_repo_unref(repo);
+       }
+
        // Close the path
        if (pakfire->fd >= 0)
                close(pakfire->fd);
@@ -535,6 +547,91 @@ ERROR:
        return r;
 }
 
+static int pakfire_setup_local_repo(struct pakfire* self) {
+       struct pakfire_repo* local = NULL;
+       char path[PATH_MAX];
+       char url[PATH_MAX];
+       int r;
+
+       // Fetch distro ID
+       const char* distro_id = pakfire_get_distro_id(self);
+       if (!distro_id) {
+               ERROR(self->ctx, "Could not fetch the distro ID\n");
+               return -EINVAL;
+       }
+
+       // Fetch the distro version ID
+       const char* version_id = pakfire_get_distro_version_id(self);
+       if (!version_id) {
+               ERROR(self->ctx, "Could not fetch the distro version ID\n");
+               return -EINVAL;
+       }
+
+       // Make the repository path
+       r = pakfire_string_format(path,
+                       "~/.local/share/%s/%s/%s", PACKAGE_NAME, distro_id, version_id);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not compose the local repository path: %s\n", strerror(-r));
+               goto ERROR;
+       }
+
+       // Expand the path
+       r = pakfire_path_expand(path, path);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not expand the local repository path: %s\n", strerror(-r));
+               goto ERROR;
+       }
+
+       // Create the path
+       r = pakfire_mkdir(path, 0700);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not create the local repository at %s: %s\n",
+                       path, strerror(-r));
+               goto ERROR;
+       }
+
+       // Create a new repository
+       r = pakfire_repo_create(&local, self, PAKFIRE_REPO_LOCAL);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not create local repository: %s\n", strerror(-r));
+               goto ERROR;
+       }
+
+       // Set description
+       r = pakfire_repo_set_description(local, _("Locally Built Packages"));
+       if (r < 0) {
+               ERROR(self->ctx, "Could not set local repository description: %s\n", strerror(-r));
+               goto ERROR;
+       }
+
+       // Compose the URL
+       r = pakfire_string_format(url, "file://%s", path);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not compose the local repository URL: %s\n", strerror(-r));
+               goto ERROR;
+       }
+
+       // Set the URL
+       r = pakfire_repo_set_baseurl(local, url);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not set local repository URL: %s\n", strerror(-r));
+               goto ERROR;
+       }
+
+       // Immediately refresh the repository
+       r = pakfire_repo_refresh(local, 0);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not refresh the local repository: %s\n", strerror(-r));
+               goto ERROR;
+       }
+
+ERROR:
+       if (local)
+               pakfire_repo_unref(local);
+
+       return r;
+}
+
 const char* pakfire_get_distro_name(struct pakfire* pakfire) {
        if (*pakfire->distro.name)
                return pakfire->distro.name;
@@ -966,6 +1063,13 @@ int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx,
        if (r < 0)
                goto ERROR;
 
+       // Setup the local repository
+       if (p->flags & (PAKFIRE_FLAGS_BUILD|PAKFIRE_FLAGS_BUILD_LOCAL)) {
+               r = pakfire_setup_local_repo(p);
+               if (r < 0)
+                       goto ERROR;
+       }
+
        // Read repository configuration
        if (p->internal_flags & PAKFIRE_HAS_PATH) {
                r = pakfire_read_repo_config(p);
index 149a80739992c9687f849ebfa58cd4fe241ba430..fa3d4831e9b8cfd3f03e918623410fec291511fa 100644 (file)
@@ -47,7 +47,8 @@ struct pakfire;
 
 enum pakfire_flags {
        PAKFIRE_FLAGS_BUILD             = (1 << 0),
-       PAKFIRE_USE_SNAPSHOT            = (1 << 1),
+       PAKFIRE_FLAGS_BUILD_LOCAL       = (1 << 1),
+       PAKFIRE_USE_SNAPSHOT            = (1 << 2),
 };
 
 // Callbacks