File 0001-platform-linux-fetch-flags-before-FS_IOC_SETFLAGS.patch of Package borgbackup

From f0be6704da2b9e4f025401caedc85a89d7280470 Mon Sep 17 00:00:00 2001
From: Jiri Slaby <jslaby@suse.cz>
Date: Tue, 7 Oct 2025 06:39:36 +0200
Subject: [PATCH] platform/linux: fetch flags before FS_IOC_SETFLAGS
References: #9039 bsc#1251048
Patch-mainline: Submitted #9040

FS_IOC_SETFLAGS called without fetching flags first can remove for
example an ext4 flag like EXT4_EXTENTS_FL which results in EOPNOTSUPP.
That one is indeed handled in the code, but this is still incorrect. The
flags should be fetched with FS_IOC_GETFLAGS, updated and only then
stored back with FS_IOC_SETFLAGS.

Fixes #9039.
Closes: https://bugzilla.suse.com/show_bug.cgi?id=1251048
---
 src/borg/platform/linux.pyx | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/borg/platform/linux.pyx b/src/borg/platform/linux.pyx
index 5ea9370cb5fe..c8f9f9e978cd 100644
--- a/src/borg/platform/linux.pyx
+++ b/src/borg/platform/linux.pyx
@@ -135,13 +135,16 @@ def set_flags(path, bsd_flags, fd=None):
             # see comment in get_flags()
             return
     cdef int flags = 0
-    for bsd_flag, linux_flag in BSD_TO_LINUX_FLAGS.items():
-        if bsd_flags & bsd_flag:
-            flags |= linux_flag
     open_fd = fd is None
     if open_fd:
         fd = os.open(path, os.O_RDONLY|os.O_NONBLOCK|os.O_NOFOLLOW)
     try:
+        if ioctl(fd, FS_IOC_GETFLAGS, &flags) == -1:
+            error_number = errno.errno
+            raise OSError(error_number, strerror(error_number).decode(), path)
+        for bsd_flag, linux_flag in BSD_TO_LINUX_FLAGS.items():
+            if bsd_flags & bsd_flag:
+                flags |= linux_flag
         if ioctl(fd, FS_IOC_SETFLAGS, &flags) == -1:
             error_number = errno.errno
             if error_number != errno.EOPNOTSUPP:
-- 
2.51.0

openSUSE Build Service is sponsored by