]> git.ipfire.org Git - pakfire.git/commitdiff
file: Ensure that all desired digests are computed
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Sep 2022 18:02:17 +0000 (18:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Sep 2022 18:02:17 +0000 (18:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c

index 16669504f465b84f6183de0faecdd471e6c78464..15c8e276526534f6a11f0f14c870481f3eaf4f8d 100644 (file)
@@ -272,6 +272,7 @@ ERROR:
 
 struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file, int digest_types) {
        const char* path = NULL;
+       int r;
 
        struct archive_entry* entry = archive_entry_new();
        if (!entry) {
@@ -310,6 +311,11 @@ struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file, int
        archive_entry_set_ctime(entry, pakfire_file_get_ctime(file), 0);
        archive_entry_set_mtime(entry, pakfire_file_get_mtime(file), 0);
 
+       // Compute any required file digests
+       r = pakfire_file_compute_digests(file, digest_types);
+       if (r)
+               goto ERROR;
+
        // Copy digests
 
        // SHA-3-512
@@ -349,6 +355,12 @@ struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file, int
                        file->digests.sha2_256, sizeof(file->digests.sha2_256));
 
        return entry;
+
+ERROR:
+       if (entry)
+               archive_entry_free(entry);
+
+       return NULL;
 }
 
 static void pakfire_file_free(struct pakfire_file* file) {