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