]> git.ipfire.org Git - pakfire.git/commitdiff
package: Compose cache path based on the binary digest
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Oct 2022 11:08:24 +0000 (11:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Oct 2022 11:19:34 +0000 (11:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/package.c

index ea1acedefce624ea4e741a03286cdf6720443500..6b2335b51acd41c8e714941123fea681ea1c250e 100644 (file)
@@ -580,12 +580,16 @@ PAKFIRE_EXPORT void pakfire_package_set_maintainer(struct pakfire_package* pkg,
 static int pakfire_package_make_cache_path(struct pakfire_package* pkg) {
        const char* filename = pakfire_package_get_filename(pkg);
 
-       enum pakfire_digest_types digest;
-       const char* hexdigest = pakfire_package_get_hexdigest(pkg, &digest);
+       enum pakfire_digest_types digest_type = PAKFIRE_DIGEST_UNDEFINED;
+       size_t digest_length = 0;
 
-       if (hexdigest && strlen(hexdigest) >= 3)
+       // Fetch the digest
+       const unsigned char* digest = pakfire_package_get_digest(pkg,
+               &digest_type, &digest_length);
+
+       if (digest && digest_length >= 4)
                return pakfire_cache_path(pkg->pakfire, pkg->path,
-                       "%c%c/%s/%s", hexdigest[0], hexdigest[1], hexdigest + 2, filename);
+                       "%02x/%02x/%02x/%02x/%s", digest[0], digest[1], digest[2], digest[3], filename);
 
        return pakfire_cache_path(pkg->pakfire, pkg->path, "%s", filename);
 }