]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire_package_create: Default to @dummy repository
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Sep 2021 15:54:19 +0000 (15:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Sep 2021 15:54:19 +0000 (15:54 +0000)
This makes calling this function easier as the repository argument might
be NULL.

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

index 85edf1418f800b5682c39cb0e984eff4cee4e7a4..de4c1ef20855a30b9ff5baa0d2110b47cdacd8ce 100644 (file)
@@ -372,7 +372,6 @@ PAKFIRE_EXPORT int pakfire_dist(struct pakfire* pakfire, const char* path,
 
        struct pakfire_packager* packager = NULL;
        struct pakfire_package* pkg = NULL;
-       struct pakfire_repo* repo = NULL;
 
        // Load makefile
        int r = pakfire_read_makefile(&makefile, pakfire, path, &error);
@@ -388,12 +387,8 @@ PAKFIRE_EXPORT int pakfire_dist(struct pakfire* pakfire, const char* path,
        if (r)
                goto ERROR;
 
-       repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_DUMMY);
-       if (!repo)
-               goto ERROR;
-
        // Get the package object
-       r = pakfire_parser_create_package(makefile, &pkg, repo, NULL, "src");
+       r = pakfire_parser_create_package(makefile, &pkg, NULL, NULL, "src");
        if (r)
                goto ERROR;
 
@@ -422,8 +417,6 @@ ERROR:
                pakfire_packager_unref(packager);
        if (pkg)
                pakfire_package_unref(pkg);
-       if (repo)
-               pakfire_repo_unref(repo);
        pakfire_parser_unref(makefile);
 
        return r;
index e3009c3eb147290d7510cd6c3cbb27c7929a46e9..490d13834d0afdd34515cb4548cb1426d472af65 100644 (file)
@@ -77,14 +77,32 @@ struct pakfire_package* pakfire_package_create_from_solvable(struct pakfire* pak
        return pkg;
 }
 
-PAKFIRE_EXPORT struct pakfire_package* pakfire_package_create(struct pakfire* pakfire, struct pakfire_repo* repo, const char* name, const char* evr, const char* arch) {
+PAKFIRE_EXPORT struct pakfire_package* pakfire_package_create(
+               struct pakfire* pakfire, struct pakfire_repo* repo,
+               const char* name, const char* evr, const char* arch) {
+       struct pakfire_package* pkg = NULL;
+       struct pakfire_repo* dummy = NULL;
+
+       // Default to dummy repository
+       if (!repo) {
+               dummy = pakfire_get_repo(pakfire, PAKFIRE_REPO_DUMMY);
+               if (!dummy) {
+                       errno = ENOENT;
+                       return NULL;
+               }
+
+               repo = dummy;
+       }
+
+       // Allocate a new solvable
        Id id = pakfire_repo_add_solvable(repo);
        if (!id)
-               return NULL;
+               goto ERROR;
 
-       struct pakfire_package* pkg = pakfire_package_create_from_solvable(pakfire, id);
+       // Create a new package object
+       pkg = pakfire_package_create_from_solvable(pakfire, id);
        if (!pkg)
-               return NULL;
+               goto ERROR;
 
        pkg->repo = pakfire_repo_ref(repo);
 
@@ -96,6 +114,10 @@ PAKFIRE_EXPORT struct pakfire_package* pakfire_package_create(struct pakfire* pa
        // Add self-provides
        pakfire_package_add_self_provides(pakfire, pkg, name, evr);
 
+ERROR:
+       if (dummy)
+               pakfire_repo_unref(dummy);
+
        return pkg;
 }