]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Improve SOLV file
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 20 Sep 2022 09:59:20 +0000 (09:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 20 Sep 2022 09:59:20 +0000 (09:59 +0000)
Add all addefileprovides and a meta section (as in tools_write in the
libsolv examples).

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/repo.c

index 822f97cccf0e16986c42310d53215a36395ef38c..68acb8eddb57f2cd3b424b701e8524cb8712a5e4 100644 (file)
@@ -887,20 +887,60 @@ PAKFIRE_EXPORT int pakfire_repo_read_solv(struct pakfire_repo* repo, FILE *f, in
 }
 
 PAKFIRE_EXPORT int pakfire_repo_write_solv(struct pakfire_repo* repo, FILE *f, int flags) {
+       Repodata* meta = NULL;
+       Queue addedfileprovides;
+       int r;
+
        pakfire_pool_internalize(repo->pakfire);
 
+       // Initialize file provides
+       queue_init(&addedfileprovides);
+
+       // Create another repodata section for meta information
+       meta = repo_add_repodata(repo->repo, 0);
+       if (!meta) {
+               ERROR(repo->pakfire, "Could not create meta repodata: %m\n");
+               r = 1;
+               goto ERROR;
+       }
+
+       // Set tool version
+       repodata_set_str(meta, SOLVID_META, REPOSITORY_TOOLVERSION, LIBSOLV_TOOLVERSION);
+
+       // Do not propagate this
+       repodata_unset(meta, SOLVID_META, REPOSITORY_EXTERNAL);
+
+       // Fetch file provides from pool
+       pool_addfileprovides_queue(repo->repo->pool, &addedfileprovides, 0);
+       if (addedfileprovides.count)
+               repodata_set_idarray(meta, SOLVID_META,
+                       REPOSITORY_ADDEDFILEPROVIDES, &addedfileprovides);
+       else
+               repodata_unset(meta, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES);
+
+       // Free some memory
+       pool_freeidhashes(repo->repo->pool);
+
+       // Internalize the repository data
+       repodata_internalize(meta);
+
        // Export repository data
-       int r = repo_write(repo->repo, f);
+       r = repo_write(repo->repo, f);
        if (r)
-               return r;
+               goto ERROR;
 
        // Flush buffers
        r = fflush(f);
        if (r) {
                ERROR(repo->pakfire, "Could not flush after writing repository: %m\n");
-               return r;
+               goto ERROR;
        }
 
+ERROR:
+       if (meta)
+               repodata_free(meta);
+       queue_free(&addedfileprovides);
+
        return r;
 }