chantra / rpms / librepo

Forked from rpms/librepo 2 years ago
Clone
e660d2
From ef9af538ccb532e15dc39ec0dc648a06c9c349a1 Mon Sep 17 00:00:00 2001
e660d2
From: Matthew Almond <malmond@fb.com>
e660d2
Date: Fri, 13 Nov 2020 16:21:17 -0800
e660d2
Subject: [PATCH] Sync data before writing checksum xattr
e660d2
e660d2
Writes to extended attributes are considered metadata, so can be
e660d2
commited to storage before data is fully synced. The upshot of this is
e660d2
that the checksum is cached but the file could be truncated. We attempt
e660d2
to sync data first to mitigate this problem.
e660d2
---
e660d2
 librepo/checksum.c | 6 ++++++
e660d2
 1 file changed, 6 insertions(+)
e660d2
e660d2
diff --git a/librepo/checksum.c b/librepo/checksum.c
e660d2
index 678803ce..dae9e0a7 100644
e660d2
--- a/librepo/checksum.c
e660d2
+++ b/librepo/checksum.c
e660d2
@@ -250,6 +250,12 @@ lr_checksum_fd_compare(LrChecksumType type,
e660d2
 
e660d2
     *matches = (strcmp(expected, checksum)) ? FALSE : TRUE;
e660d2
 
e660d2
+    if (fsync(fd) != 0) {
e660d2
+        g_set_error(err, LR_CHECKSUM_ERROR, LRE_FILE,
e660d2
+                    "fsync failed: %s", strerror(errno));
e660d2
+        return FALSE;
e660d2
+    }
e660d2
+
e660d2
     if (caching && *matches) {
e660d2
         // Store checksum as extended file attribute if caching is enabled
e660d2
         struct stat st;