]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Allow passing NULL as repo when making a package
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Aug 2021 10:47:29 +0000 (10:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Aug 2021 10:47:29 +0000 (10:47 +0000)
This makes using this function easier because it will automatically use
the @dummy repository to store any metadata

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

index 870feb453cf71844e683584316e0830a6ccb75b3..0b60b29802180c2164c36b54bc89f22415521420 100644 (file)
@@ -473,13 +473,7 @@ PAKFIRE_EXPORT struct pakfire* pakfire_archive_get_pakfire(struct pakfire_archiv
 
 static struct pakfire_package* pakfire_archive_get_package(struct pakfire_archive* archive) {
        if (!archive->package) {
-               struct pakfire_repo* repo = pakfire_get_repo(archive->pakfire, "@dummy");
-               if (!repo)
-                       return NULL;
-
-               int r = pakfire_archive_make_package(archive, repo, &archive->package);
-               pakfire_repo_unref(repo);
-
+               int r = pakfire_archive_make_package(archive, NULL, &archive->package);
                if (!r)
                        return NULL;
        }
@@ -1840,6 +1834,17 @@ PAKFIRE_EXPORT ssize_t pakfire_archive_get_size(struct pakfire_archive* archive)
 */
 PAKFIRE_EXPORT int pakfire_archive_make_package(struct pakfire_archive* archive,
                struct pakfire_repo* repo, struct pakfire_package** package) {
+       struct pakfire_repo* dummy = NULL;
+
+       // Use dummy repo if no repository was passed
+       if (!repo) {
+               dummy = pakfire_get_repo(archive->pakfire, "@dummy");
+               if (!dummy)
+                       return 1;
+
+               repo = dummy;
+       }
+
        char* name = pakfire_archive_get(archive, "package", "name");
        char* arch = pakfire_archive_get(archive, "package", "arch");
 
@@ -2019,6 +2024,10 @@ PAKFIRE_EXPORT int pakfire_archive_make_package(struct pakfire_archive* archive,
 
        *package = pkg;
 
+       // Cleanup
+       if (dummy)
+               pakfire_repo_unref(dummy);
+
        return 0;
 }