return r;
}
+int pakfire_digests_compute_from_path(struct pakfire_ctx* ctx,
+ struct pakfire_digests* digests, int types, const char* path) {
+ FILE* f = NULL;
+ int r;
+
+ // Open the file
+ f = fopen(path, "r");
+ if (!f)
+ return -errno;
+
+ // Compute the digests
+ r = pakfire_digests_compute_from_file(ctx, digests, types, f);
+
+ // Close the file
+ if (f)
+ fclose(f);
+
+ return r;
+}
+
static void pakfire_digests_compare_mismatch(struct pakfire_ctx* ctx, const char* what,
const unsigned char* digest1, const unsigned char* digest2, const size_t length) {
char* hexdigest1 = __pakfire_hexlify(digest1, length);
PAKFIRE_DIGEST_SHA3_512 = (1 << 5),
};
-#define PAKFIRE_DIGESTS_ALL (~PAKFIRE_DIGEST_UNDEFINED)
+#define PAKFIRE_DIGESTS_ALL ( \
+ PAKFIRE_DIGEST_SHA2_256 | \
+ PAKFIRE_DIGEST_SHA2_512 | \
+ PAKFIRE_DIGEST_BLAKE2S256 | \
+ PAKFIRE_DIGEST_BLAKE2B512 | \
+ PAKFIRE_DIGEST_SHA3_256 | \
+ PAKFIRE_DIGEST_SHA3_512 \
+)
+
+#define PAKFIRE_DIGESTS_FOREACH(digest) \
+ for (digest = 1; digest & PAKFIRE_DIGESTS_ALL; digest <<= 1)
#include <pakfire/ctx.h>
int pakfire_digests_compute_from_file(struct pakfire_ctx* ctx,
struct pakfire_digests* digests, int types, FILE* f);
+int pakfire_digests_compute_from_path(struct pakfire_ctx* ctx,
+ struct pakfire_digests* digests, int types, const char* path);
int pakfire_digests_compare(struct pakfire_ctx* ctx, const struct pakfire_digests* digests1,
const struct pakfire_digests* digests2, const int types);
return 0;
}
-static int pakfire_repo_metadata_add_file(
- struct pakfire_repo* self, struct json_object* repomd, const char* filename) {
+static int pakfire_repo_metadata_add_file(struct pakfire_repo* self,
+ struct json_object* repomd, const char* path) {
+ struct pakfire_digests digests = {};
struct json_object* files = NULL;
struct json_object* file = NULL;
+ struct json_object* chksums = NULL;
+ char filename[PATH_MAX];
+ char* hexdigest = NULL;
+ int digest;
int r;
+ // Make the filename
+ r = pakfire_path_basename(filename, path);
+ if (r < 0)
+ goto ERROR;
+
+ // Compute the database digests
+ r = pakfire_digests_compute_from_path(self->ctx, &digests, PAKFIRE_DIGESTS_ALL, path);
+ if (r < 0) {
+ ERROR(self->ctx, "Failed to compute file digests: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
// Fetch the files array
files = json_object_object_get(repomd, "files");
if (!files) {
if (r < 0)
goto ERROR;
+ // Add checksums
+ r = pakfire_json_add_object(file, "chksums", &chksums);
+ if (r < 0)
+ goto ERROR;
+
+ // Add all digests
+ PAKFIRE_DIGESTS_FOREACH(digest) {
+ hexdigest = pakfire_digest_get_hex(&digests, digest);
+
+ if (hexdigest) {
+ r = pakfire_json_add_string(chksums, pakfire_digest_name(digest), hexdigest);
+ if (r < 0)
+ goto ERROR;
+
+ free(hexdigest);
+ hexdigest = NULL;
+ }
+ }
+
// Append it to the files array
r = json_object_array_add(files, file);
if (r < 0) {
ERROR:
if (file)
json_object_put(file);
+ if (hexdigest)
+ free(hexdigest);
return r;
}
}
// Add the database to the filelist
- r = pakfire_repo_metadata_add_file(self, repomd, filename);
+ r = pakfire_repo_metadata_add_file(self, repomd, database);
if (r < 0)
goto ERROR;