]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Add the database path to the repository metadata
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 2 Feb 2025 13:48:58 +0000 (13:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 2 Feb 2025 13:48:58 +0000 (13:48 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/repo.c

index a5f98764290aa04b2d73cea6d482650d7d7186b7..8309fe4b7b2d6923e4ff6e43b0e5776ba351a18c 100644 (file)
@@ -1965,35 +1965,35 @@ int pakfire_repo_refresh(struct pakfire_repo* repo, int force) {
        return 0;
 }
 
-static int pakfire_repo_write_database(
-               struct pakfire_repo* repo, char* filename, size_t length) {
+static int pakfire_repo_write_database(struct pakfire_repo* self,
+               struct json_object* repomd, char* filename, size_t length) {
        char database[PATH_MAX];
        char tmp[PATH_MAX];
        int r;
 
        // Create path for a temporary database export file
-       r = pakfire_repo_path(repo, tmp, "%s", "repodata/.pakfire-solv.XXXXXX");
+       r = pakfire_repo_path(self, tmp, "%s", "repodata/.pakfire-solv.XXXXXX");
        if (r < 0)
                return r;
 
        // Create a temporary file to write to
        FILE* f = pakfire_mktemp(tmp, 0644);
        if (!f) {
-               ERROR(repo->ctx, "Could not open temporary file for writing: %m\n");
+               ERROR(self->ctx, "Could not open temporary file for writing: %m\n");
                return 1;
        }
 
        // Initialize the output being compressed
        f = pakfire_zstdfopen(f, "w19");
        if (!f) {
-               ERROR(repo->ctx, "Could not initialize compression: %m\n");
+               ERROR(self->ctx, "Could not initialize compression: %m\n");
                return 1;
        }
 
        // Write the SOLV database to the temporary file
-       r = pakfire_repo_write_solv(repo, f, 0);
+       r = pakfire_repo_write_solv(self, f, 0);
        if (r) {
-               ERROR(repo->ctx, "Could not write SOLV data: %m\n");
+               ERROR(self->ctx, "Could not write SOLV data: %m\n");
                goto ERROR;
        }
 
@@ -2004,25 +2004,30 @@ static int pakfire_repo_write_database(
        // Create a filename for the database file
        r = __pakfire_strftime_now(filename, length, "%Y-%m-%d-%H%M.%s.solv.zst");
        if (r) {
-               ERROR(repo->ctx, "Could not format database filename: %m\n");
+               ERROR(self->ctx, "Could not format database filename: %m\n");
                goto ERROR;
        }
 
        // Make final database path
-       r = pakfire_repo_path(repo, database, "repodata/%s", filename);
+       r = pakfire_repo_path(self, database, "repodata/%s", filename);
        if (r < 0) {
-               ERROR(repo->ctx, "Could not join database path: %m\n");
+               ERROR(self->ctx, "Could not join database path: %m\n");
                goto ERROR;
        }
 
        // Link database to its destination
        r = link(tmp, database);
        if (r < 0) {
-               ERROR(repo->ctx, "Could not link database %s: %m\n", database);
+               ERROR(self->ctx, "Could not link database %s: %m\n", database);
                r = -errno;
                goto ERROR;
        }
 
+       // Add the database name to the repository metadata
+       r = pakfire_json_add_string(repomd, "database", filename);
+       if (r < 0)
+               goto ERROR;
+
 ERROR:
        if (f)
                fclose(f);
@@ -2074,11 +2079,6 @@ int pakfire_repo_write_metadata(struct pakfire_repo* self, struct pakfire_key* k
        if (r < 0)
                goto ERROR;
 
-       // Write the database
-       r = pakfire_repo_write_database(self, database, sizeof(database));
-       if (r < 0)
-               goto ERROR;
-
        // Compose JSON object
        repomd = json_object_new_object();
        if (!repomd) {
@@ -2092,6 +2092,11 @@ int pakfire_repo_write_metadata(struct pakfire_repo* self, struct pakfire_key* k
        if (r < 0)
                goto ERROR;
 
+       // Write the database
+       r = pakfire_repo_write_database(self, repomd, database, sizeof(database));
+       if (r < 0)
+               goto ERROR;
+
        // XXX database hash is missing
 
        // Open repomd.json for writing