From: Michael Tremer Date: Tue, 28 Sep 2021 15:54:19 +0000 (+0000) Subject: pakfire_package_create: Default to @dummy repository X-Git-Tag: 0.9.28~918 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32136e0c99a3975a7199fd7c8f4500fdc014c5b1;p=pakfire.git pakfire_package_create: Default to @dummy repository This makes calling this function easier as the repository argument might be NULL. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index 85edf1418..de4c1ef20 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -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; diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index e3009c3eb..490d13834 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -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; }