Backport patch: Use nanosec precision for timestamp of checksum cache

Resolves: rhbz#2077859
This commit is contained in:
Lukáš Hrázký 2022-07-12 12:54:07 +02:00
parent 62f6934cd7
commit 0a765d0964
2 changed files with 78 additions and 1 deletions

View File

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

View File

@ -12,13 +12,15 @@
Name: librepo Name: librepo
Version: 1.14.2 Version: 1.14.2
Release: 1%{?dist} Release: 2%{?dist}
Summary: Repodata downloading library Summary: Repodata downloading library
License: LGPLv2+ License: LGPLv2+
URL: https://github.com/rpm-software-management/librepo URL: https://github.com/rpm-software-management/librepo
Source0: %{url}/archive/%{version}/%{name}-%{version}.tar.gz Source0: %{url}/archive/%{version}/%{name}-%{version}.tar.gz
Patch0001: 0001-Use-nanosec-precision-for-timestamp-of-checksum-cach.patch
BuildRequires: cmake BuildRequires: cmake
BuildRequires: gcc BuildRequires: gcc
BuildRequires: check-devel BuildRequires: check-devel
@ -96,6 +98,9 @@ Python 3 bindings for the librepo library.
%{python3_sitearch}/%{name}/ %{python3_sitearch}/%{name}/
%changelog %changelog
* Tue Jul 12 2022 Lukas Hrazky <lhrazky@redhat.com> - 1.14.2-2
- Use nanosec precision for timestamp of checksum cache
* Mon Oct 25 2021 Pavla Kratochvilova <pkratoch@redhat.com> - 1.14.2-1 * Mon Oct 25 2021 Pavla Kratochvilova <pkratoch@redhat.com> - 1.14.2-1
- Update to 1.14.2 - Update to 1.14.2
- Reduce time to load metadata - Reduce time to load metadata