]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Revert "copy: Copy file attributes as well"
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 23 Aug 2024 10:24:16 +0000 (12:24 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 4 Sep 2024 16:49:05 +0000 (18:49 +0200)
This reverts commit 2356104efcc599439c887b087da83fbeca1fa9a6.

src/shared/copy.c

index 8e240dc434f933295aabb52142bbf534c0a543e8..abebe2d2f223eb214c5d26d2fade5f1c136c3485 100644 (file)
@@ -798,7 +798,6 @@ static int fd_copy_regular(
                 void *userdata) {
 
         _cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
-        unsigned attrs = 0;
         int r, q;
 
         assert(st);
@@ -814,10 +813,6 @@ static int fd_copy_regular(
         if (fdf < 0)
                 return fdf;
 
-        r = read_attr_fd(fdf, &attrs);
-        if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r) && r != -ELOOP)
-                return r;
-
         if (copy_flags & COPY_MAC_CREATE) {
                 r = mac_selinux_create_file_prepare_at(dt, to, S_IFREG);
                 if (r < 0)
@@ -829,9 +824,6 @@ static int fd_copy_regular(
         if (fdt < 0)
                 return -errno;
 
-        if (attrs != 0)
-                (void) chattr_full(fdt, NULL, attrs, CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
-
         r = copy_bytes_full(fdf, fdt, UINT64_MAX, copy_flags, NULL, NULL, progress, userdata);
         if (r < 0)
                 goto fail;
@@ -847,9 +839,6 @@ static int fd_copy_regular(
         (void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim });
         (void) copy_xattr(fdf, NULL, fdt, NULL, copy_flags);
 
-        if (attrs != 0)
-                (void) chattr_full(fdt, NULL, attrs, ~CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
-
         if (FLAGS_SET(copy_flags, COPY_VERIFY_LINKED)) {
                 r = fd_verify_linked(fdf);
                 if (r < 0)
@@ -1430,7 +1419,6 @@ int copy_file_at_full(
 
         _cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
         struct stat st;
-        unsigned attrs = 0;
         int r;
 
         assert(dir_fdf >= 0 || dir_fdf == AT_FDCWD);
@@ -1448,10 +1436,6 @@ int copy_file_at_full(
         if (r < 0)
                 return r;
 
-        r = read_attr_at(dir_fdf, from, &attrs);
-        if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r) && r != -ELOOP)
-                return r;
-
         WITH_UMASK(0000) {
                 fdt = xopenat_lock_full(dir_fdt, to,
                                         flags|O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY,
@@ -1468,10 +1452,8 @@ int copy_file_at_full(
                         goto fail;
         }
 
-        attrs = (attrs & ~chattr_mask) | (chattr_flags & chattr_mask);
-
-        if (attrs != 0)
-                (void) chattr_full(fdt, NULL, attrs, CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
+        if (chattr_mask != 0)
+                (void) chattr_fd(fdt, chattr_flags, chattr_mask & CHATTR_EARLY_FL, NULL);
 
         r = copy_bytes_full(fdf, fdt, UINT64_MAX, copy_flags & ~COPY_LOCK_BSD, NULL, NULL, progress_bytes, userdata);
         if (r < 0)
@@ -1486,8 +1468,8 @@ int copy_file_at_full(
                         goto fail;
         }
 
-        if (attrs != 0)
-                (void) chattr_full(fdt, NULL, attrs, ~CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
+        if (chattr_mask != 0)
+                (void) chattr_fd(fdt, chattr_flags, chattr_mask & ~CHATTR_EARLY_FL, NULL);
 
         if (copy_flags & (COPY_FSYNC|COPY_FSYNC_FULL)) {
                 if (fsync(fdt) < 0) {
@@ -1532,7 +1514,6 @@ int copy_file_atomic_at_full(
 
         _cleanup_(unlink_and_freep) char *t = NULL;
         _cleanup_close_ int fdt = -EBADF;
-        unsigned attrs = 0;
         int r;
 
         assert(to);
@@ -1549,14 +1530,8 @@ int copy_file_atomic_at_full(
         if (fdt < 0)
                 return fdt;
 
-        r = read_attr_at(dir_fdf, from, &attrs);
-        if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r) && r != -ELOOP)
-                return r;
-
-        attrs = (attrs & ~chattr_mask) | (chattr_flags & chattr_mask);
-
-        if (attrs != 0)
-                (void) chattr_full(fdt, NULL, attrs, CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
+        if (chattr_mask != 0)
+                (void) chattr_fd(fdt, chattr_flags, chattr_mask & CHATTR_EARLY_FL, NULL);
 
         r = copy_file_fd_at_full(dir_fdf, from, fdt, copy_flags, progress_bytes, userdata);
         if (r < 0)
@@ -1577,8 +1552,8 @@ int copy_file_atomic_at_full(
 
         t = mfree(t);
 
-        if (attrs != 0)
-                (void) chattr_full(fdt, NULL, attrs, ~CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
+        if (chattr_mask != 0)
+                (void) chattr_fd(fdt, chattr_flags, chattr_mask & ~CHATTR_EARLY_FL, NULL);
 
         r = close_nointr(TAKE_FD(fdt)); /* even if this fails, the fd is now invalidated */
         if (r < 0)