From: Michael Tremer Date: Thu, 23 Sep 2021 10:28:09 +0000 (+0000) Subject: file: Copy digests from libarchive mtrees X-Git-Tag: 0.9.28~932 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa8ea50c9fb1b89f4c371c55fbd91d11363d895e;p=pakfire.git file: Copy digests from libarchive mtrees Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index 6cdc22595..0ed5269e1 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -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) {