]> git.ipfire.org Git - pakfire.git/commitdiff
file: Copy digests from libarchive mtrees
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 23 Sep 2021 10:28:09 +0000 (10:28 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 23 Sep 2021 10:28:09 +0000 (10:28 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c

index 6cdc22595f8ee878c6e16280a1b887d440897d1f..0ed5269e12200cd5fbbdd96ee912dd22350a2ee0 100644 (file)
@@ -127,7 +127,19 @@ struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file) {
        return entry;
 }
 
+static const struct pakfire_libarchive_digest {
+       enum pakfire_digests pakfire;
+       int libarchive;
+} pakfire_libarchive_digests[] = {
+       { PAKFIRE_DIGEST_SHA512, ARCHIVE_ENTRY_DIGEST_SHA512 },
+       { PAKFIRE_DIGEST_SHA256, ARCHIVE_ENTRY_DIGEST_SHA256 },
+       { PAKFIRE_DIGEST_SHA1, ARCHIVE_ENTRY_DIGEST_SHA1 },
+       { PAKFIRE_DIGEST_NONE, 0 },
+};
+
 int pakfire_file_copy_archive_entry(struct pakfire_file* file, struct archive_entry* entry) {
+       int r = 0;
+
        // Set abspath
        pakfire_file_set_abspath(file, archive_entry_sourcepath(entry));
 
@@ -150,9 +162,20 @@ int pakfire_file_copy_archive_entry(struct pakfire_file* file, struct archive_en
        pakfire_file_set_ctime(file, archive_entry_ctime(entry));
        pakfire_file_set_mtime(file, archive_entry_mtime(entry));
 
-       // XXX copy digest
+       // Copy digest
+       for (const struct pakfire_libarchive_digest* type = pakfire_libarchive_digests;
+                       type->pakfire; type++) {
+               const unsigned char* digest = archive_entry_digest(entry, type->libarchive);
+               if (digest) {
+                       r = pakfire_file_set_digest(file, type->pakfire, digest);
+                       if (r)
+                               return r;
 
-       return 0;
+                       break;
+               }
+       }
+
+       return r;
 }
 
 static void pakfire_file_free(struct pakfire_file* file) {