From: Michael Tremer Date: Tue, 25 Oct 2022 17:04:19 +0000 (+0000) Subject: packages: Move pakfire_package_get_source_package into string function X-Git-Tag: 0.9.28~212 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=73ff505b11fc7ff4dc4d18227e21f4d41590bf9d;p=pakfire.git packages: Move pakfire_package_get_source_package into string function Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/package.c b/src/_pakfire/package.c index 4198b8cc6..0811d3ee0 100644 --- a/src/_pakfire/package.c +++ b/src/_pakfire/package.c @@ -649,7 +649,9 @@ static PyObject* Package_dump(PackageObject* self, PyObject *args, PyObject* kwd } static PyObject* Package_get_source_package(PackageObject* self) { - const char* source_package = pakfire_package_get_source_package(self->package); + const char* source_package = pakfire_package_get_string(self->package, PAKFIRE_PKG_SOURCE_PKG); + if (!source_package) + Py_RETURN_NONE; return PyUnicode_FromString(source_package); } diff --git a/src/libpakfire/include/pakfire/package.h b/src/libpakfire/include/pakfire/package.h index 492207db1..fb218ff7e 100644 --- a/src/libpakfire/include/pakfire/package.h +++ b/src/libpakfire/include/pakfire/package.h @@ -50,6 +50,7 @@ enum pakfire_package_key { PAKFIRE_PKG_FILENAME, PAKFIRE_PKG_BUILD_HOST, PAKFIRE_PKG_BUILD_ID, + PAKFIRE_PKG_SOURCE_PKG, }; int pakfire_package_create(struct pakfire_package** package, struct pakfire* pakfire, @@ -90,7 +91,6 @@ time_t pakfire_package_get_build_time(struct pakfire_package* pkg); void pakfire_package_set_build_time(struct pakfire_package* pkg, time_t build_time); time_t pakfire_package_get_install_time(struct pakfire_package* pkg); void pakfire_package_set_install_time(struct pakfire_package* pkg, time_t install_time); -const char* pakfire_package_get_source_package(struct pakfire_package* pkg); const char* pakfire_package_get_source_name(struct pakfire_package* pkg); void pakfire_package_set_source_name(struct pakfire_package* pkg, const char* name); const char* pakfire_package_get_source_evr(struct pakfire_package* pkg); diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 23cc716d4..41a27cafc 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -190,7 +190,6 @@ global: pakfire_package_get_source_arch; pakfire_package_get_source_evr; pakfire_package_get_source_name; - pakfire_package_get_source_package; pakfire_package_get_string; pakfire_package_get_suggests; pakfire_package_get_supplements; diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 4e58b0512..9b13874dc 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -403,6 +403,24 @@ PAKFIRE_EXPORT const char* pakfire_package_get_string( case PAKFIRE_PKG_BUILD_ID: ret = solvable_lookup_str(s, SOLVABLE_BUILDVERSION); break; + + case PAKFIRE_PKG_SOURCE_PKG: + if (!*pkg->source_nevra) { + const char* name = pakfire_package_get_source_name(pkg); + const char* evr = pakfire_package_get_source_evr(pkg); + const char* arch = pakfire_package_get_source_arch(pkg); + + // Return nothing if we don't have all information + if (!name || !evr || !arch) + return NULL; + + // Format package name + r = pakfire_string_format(pkg->source_nevra, "%s-%s.%s", name, evr, arch); + if (r) + return NULL; + } + + return pkg->source_nevra; } return ret; @@ -493,6 +511,10 @@ PAKFIRE_EXPORT int pakfire_package_set_string( case PAKFIRE_PKG_BUILD_ID: id = SOLVABLE_BUILDVERSION; break; + + case PAKFIRE_PKG_SOURCE_PKG: + // The source package name cannot be set + break; } // Check if we have found a valid ID @@ -757,23 +779,6 @@ PAKFIRE_EXPORT void pakfire_package_set_install_time(struct pakfire_package* pkg pakfire_package_set_num(pkg, SOLVABLE_INSTALLTIME, install_time); } -PAKFIRE_EXPORT const char* pakfire_package_get_source_package(struct pakfire_package* pkg) { - if (!*pkg->source_nevra) { - const char* name = pakfire_package_get_source_name(pkg); - const char* evr = pakfire_package_get_source_evr(pkg); - const char* arch = pakfire_package_get_source_arch(pkg); - - // Return nothing if we don't have all information - if (!name || !evr || !arch) - return NULL; - - // Format package name - pakfire_string_format(pkg->source_nevra, "%s-%s.%s", name, evr, arch); - } - - return pkg->source_nevra; -} - PAKFIRE_EXPORT const char* pakfire_package_get_source_name(struct pakfire_package* pkg) { return pakfire_package_get_string(pkg, SOLVABLE_SOURCENAME); } @@ -1197,7 +1202,7 @@ PAKFIRE_EXPORT char* pakfire_package_dump(struct pakfire_package* pkg, int flags } // Source package - const char* source_package = pakfire_package_get_source_package(pkg); + const char* source_package = pakfire_package_get_string(pkg, PAKFIRE_PKG_SOURCE_PKG); if (source_package) pakfire_package_dump_add_line(&string, _("Source Package"), source_package);