|
|
caa9de |
From e6f48ae9bff7b5dc8027d043aa1bffa53d507a42 Mon Sep 17 00:00:00 2001
|
|
|
caa9de |
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
|
|
|
caa9de |
Date: Thu, 5 May 2022 12:44:27 +0200
|
|
|
caa9de |
Subject: [PATCH] Use nanosec precision for timestamp of checksum cache
|
|
|
caa9de |
(RhBug:2077864)
|
|
|
caa9de |
|
|
|
caa9de |
= changelog =
|
|
|
caa9de |
msg: Use nanosec precision for timestamp of checksum cache
|
|
|
caa9de |
type: bugfix
|
|
|
caa9de |
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2077864
|
|
|
caa9de |
---
|
|
|
caa9de |
librepo/checksum.c | 7 +++++--
|
|
|
caa9de |
tests/test_checksum.c | 6 +++++-
|
|
|
caa9de |
2 files changed, 10 insertions(+), 3 deletions(-)
|
|
|
caa9de |
|
|
|
caa9de |
diff --git a/librepo/checksum.c b/librepo/checksum.c
|
|
|
caa9de |
index 6bba53c..d82cb5c 100644
|
|
|
caa9de |
--- a/librepo/checksum.c
|
|
|
caa9de |
+++ b/librepo/checksum.c
|
|
|
caa9de |
@@ -18,6 +18,7 @@
|
|
|
caa9de |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
caa9de |
*/
|
|
|
caa9de |
|
|
|
caa9de |
+#define _POSIX_C_SOURCE 200809L
|
|
|
caa9de |
#include <glib.h>
|
|
|
caa9de |
#include <glib/gprintf.h>
|
|
|
caa9de |
#include <assert.h>
|
|
|
caa9de |
@@ -217,16 +218,18 @@ lr_checksum_fd_compare(LrChecksumType type,
|
|
|
caa9de |
return FALSE;
|
|
|
caa9de |
}
|
|
|
caa9de |
|
|
|
caa9de |
- time_t timestamp = -1;
|
|
|
caa9de |
+ long long timestamp = -1;
|
|
|
caa9de |
|
|
|
caa9de |
if (caching) {
|
|
|
caa9de |
struct stat st;
|
|
|
caa9de |
if (fstat(fd, &st) == 0) {
|
|
|
caa9de |
timestamp = st.st_mtime;
|
|
|
caa9de |
+ timestamp *= 1000000000; //convert sec timestamp to nanosec timestamp
|
|
|
caa9de |
+ timestamp += st.st_mtim.tv_nsec;
|
|
|
caa9de |
}
|
|
|
caa9de |
}
|
|
|
caa9de |
|
|
|
caa9de |
- _cleanup_free_ gchar *timestamp_str = g_strdup_printf("%lli", (long long)timestamp);
|
|
|
caa9de |
+ _cleanup_free_ gchar *timestamp_str = g_strdup_printf("%lli", timestamp);
|
|
|
caa9de |
const char *type_str = lr_checksum_type_to_str(type);
|
|
|
caa9de |
_cleanup_free_ gchar *timestamp_key = g_strconcat(XATTR_CHKSUM_PREFIX, "mtime", NULL);
|
|
|
caa9de |
_cleanup_free_ gchar *checksum_key = g_strconcat(XATTR_CHKSUM_PREFIX, type_str, NULL);
|
|
|
caa9de |
diff --git a/tests/test_checksum.c b/tests/test_checksum.c
|
|
|
caa9de |
index cd28cd1..548f588 100644
|
|
|
caa9de |
--- a/tests/test_checksum.c
|
|
|
caa9de |
+++ b/tests/test_checksum.c
|
|
|
caa9de |
@@ -1,3 +1,4 @@
|
|
|
caa9de |
+#define _POSIX_C_SOURCE 200809L
|
|
|
caa9de |
#define _GNU_SOURCE
|
|
|
caa9de |
#include <errno.h>
|
|
|
caa9de |
#include <stdlib.h>
|
|
|
caa9de |
@@ -150,7 +151,10 @@ START_TEST(test_cached_checksum_matches)
|
|
|
caa9de |
// stored timestamp matches the file mtime
|
|
|
caa9de |
ret = stat(filename, &st);
|
|
|
caa9de |
ck_assert_int_eq(ret, 0);
|
|
|
caa9de |
- mtime_str = g_strdup_printf("%lli", (long long) st.st_mtime);
|
|
|
caa9de |
+ long long timestamp = st.st_mtime;
|
|
|
caa9de |
+ timestamp *= 1000000000; //convert sec timestamp to nanosec timestamp
|
|
|
caa9de |
+ timestamp += st.st_mtim.tv_nsec;
|
|
|
caa9de |
+ mtime_str = g_strdup_printf("%lli", timestamp);
|
|
|
caa9de |
attr_ret = GETXATTR(filename, timestamp_key, &buf, sizeof(buf)-1);
|
|
|
caa9de |
ck_assert(attr_ret != -1);
|
|
|
caa9de |
buf[attr_ret] = 0;
|
|
|
caa9de |
--
|
|
|
caa9de |
2.36.1
|
|
|
caa9de |
|