From: Michael Tremer Date: Tue, 25 Oct 2022 16:58:30 +0000 (+0000) Subject: packages: Add functions to easily set UUIDs X-Git-Tag: 0.9.28~213 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3bea955d32d39817512a783fc5082e6386187923;p=pakfire.git packages: Add functions to easily set UUIDs Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 7eb353740..51b82b8d9 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -543,7 +543,7 @@ static int pakfire_build_package(struct pakfire_build* build, struct pakfire_par } // Set build ID - pakfire_package_set_build_id_from_uuid(pkg, &build->id); + pakfire_package_set_uuid(pkg, PAKFIRE_PKG_BUILD_ID, build->id); // Set source package const char* source_name = pakfire_parser_get(makefile, NULL, "name"); diff --git a/src/libpakfire/include/pakfire/package.h b/src/libpakfire/include/pakfire/package.h index 5d3e52653..492207db1 100644 --- a/src/libpakfire/include/pakfire/package.h +++ b/src/libpakfire/include/pakfire/package.h @@ -23,6 +23,8 @@ #include +#include + struct pakfire_package; #include @@ -61,11 +63,18 @@ int pakfire_package_eq(struct pakfire_package* pkg1, struct pakfire_package* pkg int pakfire_package_cmp(struct pakfire_package* pkg1, struct pakfire_package* pkg2); int pakfire_package_evr_cmp(struct pakfire_package* pkg1, struct pakfire_package* pkg2); +// String const char* pakfire_package_get_string(struct pakfire_package* pkg, const enum pakfire_package_key key); int pakfire_package_set_string(struct pakfire_package* pkg, const enum pakfire_package_key key, const char* value); +// UUID +int pakfire_package_get_uuid(struct pakfire_package* pkg, + const enum pakfire_package_key key, uuid_t uuid); +int pakfire_package_set_uuid(struct pakfire_package* pkg, + const enum pakfire_package_key key, const uuid_t uuid); + const unsigned char* pakfire_package_get_digest(struct pakfire_package* pkg, enum pakfire_digest_types* type, size_t* length); int pakfire_package_set_digest(struct pakfire_package* pkg, @@ -124,11 +133,9 @@ enum pakfire_package_dump_flags { #include #include -#include int pakfire_package_create_from_solvable(struct pakfire_package** package, struct pakfire* pakfire, Id id); -void pakfire_package_set_build_id_from_uuid(struct pakfire_package* pkg, uuid_t* build_id); uint64_t pakfire_package_get_dbid(struct pakfire_package* pkg); void pakfire_package_set_dbid(struct pakfire_package* pkg, uint64_t id); diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 20b2b3def..23cc716d4 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -194,6 +194,7 @@ global: pakfire_package_get_string; pakfire_package_get_suggests; pakfire_package_get_supplements; + pakfire_package_get_uuid; pakfire_package_ref; pakfire_package_set_build_time; pakfire_package_set_checksum; @@ -206,6 +207,7 @@ global: pakfire_package_set_source_evr; pakfire_package_set_source_name; pakfire_package_set_string; + pakfire_package_set_uuid; pakfire_package_unref; # packagelist diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 81cf4e3c7..4e58b0512 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -514,6 +514,54 @@ PAKFIRE_EXPORT int pakfire_package_set_string( return 0; } +PAKFIRE_EXPORT int pakfire_package_get_uuid(struct pakfire_package* pkg, + const enum pakfire_package_key key, uuid_t uuid) { + const char* buffer = NULL; + int r; + + switch (key) { + case PAKFIRE_PKG_UUID: + case PAKFIRE_PKG_BUILD_ID: + // Clear the UUID + uuid_clear(uuid); + + // Fetch the value + buffer = pakfire_package_get_string(pkg, key); + if (!buffer) + return 1; + + // Read buffer into the output + r = uuid_parse(buffer, uuid); + if (r) + return r; + + return 0; + + default: + errno = EINVAL; + return 1; + } +} + +PAKFIRE_EXPORT int pakfire_package_set_uuid(struct pakfire_package* pkg, + const enum pakfire_package_key key, const uuid_t uuid) { + char buffer[UUID_STR_LEN]; + + switch (key) { + case PAKFIRE_PKG_UUID: + case PAKFIRE_PKG_BUILD_ID: + // Convert the UUID to string + uuid_unparse_lower(uuid, buffer); + + // Store the UUID as string + return pakfire_package_set_string(pkg, key, buffer); + + default: + errno = EINVAL; + return 1; + } +} + static unsigned long long pakfire_package_get_num(struct pakfire_package* pkg, Id type) { pakfire_package_internalize_repo(pkg); @@ -693,15 +741,6 @@ PAKFIRE_EXPORT size_t pakfire_package_get_size(struct pakfire_package* pkg) { return pakfire_package_get_downloadsize(pkg); } -void pakfire_package_set_build_id_from_uuid(struct pakfire_package* pkg, uuid_t* build_id) { - char buffer[UUID_STR_LEN]; - - // Convert the UUID to string - uuid_unparse_lower(*build_id, buffer); - - pakfire_package_set_string(pkg, PAKFIRE_PKG_BUILD_ID, buffer); -} - PAKFIRE_EXPORT time_t pakfire_package_get_build_time(struct pakfire_package* pkg) { return pakfire_package_get_num(pkg, SOLVABLE_BUILDTIME); }