Blame SOURCES/0001-Use-nanosec-precision-for-timestamp-of-checksum-cach.patch

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