]> git.ipfire.org Git - pakfire.git/commitdiff
packages: Add functions to easily set UUIDs
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Oct 2022 16:58:30 +0000 (16:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Oct 2022 16:58:30 +0000 (16:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c
src/libpakfire/include/pakfire/package.h
src/libpakfire/libpakfire.sym
src/libpakfire/package.c

index 7eb353740d50eea572f55323e8e5f5474c5f9a6a..51b82b8d9934a9a209061dd90917bb2162c8a77c 100644 (file)
@@ -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");
index 5d3e52653c83ba9ead073c6f6563f31d459ce449..492207db157a7de942a2c6d5806c3e9ebb219d24 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <time.h>
 
+#include <uuid/uuid.h>
+
 struct pakfire_package;
 
 #include <pakfire/digest.h>
@@ -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 <json.h>
 
 #include <solv/pooltypes.h>
-#include <uuid/uuid.h>
 
 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);
index 20b2b3def540460de9a746fb30e558a52da011b3..23cc716d475162f05a06c78cc04696529f1a47be 100644 (file)
@@ -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
index 81cf4e3c7cb10198bdbddb521efe5728d2bba292..4e58b051209c450448bb63e261a7035f8751874c 100644 (file)
@@ -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);
 }