From d4aad76b9fd1da56ec42e1cde5d57e344cc9571d Mon Sep 17 00:00:00 2001
From: Matthew Almond <malmond@fb.com>
Date: Thu, 11 Mar 2021 10:41:23 -0800
Subject: [PATCH 1/2] Return "calculated" checksum if requested w/caching
If a file is downloaded via librepo (e.g. `dnf install --downloadonly`)
then a request to get the checksum via `lr_checksum_fd_compare()` will
not work. It'll only return whether the checksum is valid, and not the
actual checksum. This is the simple fix.
Addresses #233
---
librepo/checksum.c | 2 +
tests/test_checksum.c | 164 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 163 insertions(+), 3 deletions(-)
diff --git a/librepo/checksum.c b/librepo/checksum.c
index 678803c..8917176 100644
--- a/librepo/checksum.c
+++ b/librepo/checksum.c
@@ -239,6 +239,8 @@ lr_checksum_fd_compare(LrChecksumType type,
// xattr may contain null terminator (+1 byte)
*matches = (attr_size == expected_len || attr_size == expected_len + 1) &&
memcmp(expected, buf, attr_size) == 0;
+ if (calculated)
+ *calculated = g_strdup(buf);
return TRUE;
}
}