]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
copy: slightly optimize around chattr_fd() 36593/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Mar 2025 19:49:18 +0000 (04:49 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Mar 2025 19:49:18 +0000 (04:49 +0900)
src/shared/copy.c

index 789ed00181d853c9102ab994efb3540f2a98c1e2..55518d6dffbe0c9077f204236ccf16c6cb9ee469 100644 (file)
@@ -1487,7 +1487,7 @@ int copy_file_at_full(
         if (r < 0)
                 return r;
 
-        if (chattr_mask != 0)
+        if ((chattr_mask & CHATTR_EARLY_FL) != 0)
                 (void) chattr_fd(fdt, chattr_flags, chattr_mask & CHATTR_EARLY_FL);
 
         r = copy_bytes_full(fdf, fdt, UINT64_MAX, copy_flags & ~COPY_LOCK_BSD, NULL, NULL, progress_bytes, userdata);
@@ -1504,7 +1504,7 @@ int copy_file_at_full(
         }
 
         unsigned nocow = FLAGS_SET(copy_flags, COPY_NOCOW_AFTER) ? FS_NOCOW_FL : 0;
-        if ((chattr_mask | nocow) != 0)
+        if (((chattr_mask & ~CHATTR_EARLY_FL) | nocow) != 0)
                 (void) chattr_fd(fdt, chattr_flags | nocow, (chattr_mask & ~CHATTR_EARLY_FL) | nocow);
 
         if (copy_flags & (COPY_FSYNC|COPY_FSYNC_FULL)) {
@@ -1570,7 +1570,7 @@ int copy_file_atomic_at_full(
         if (r < 0)
                 return r;
 
-        if (chattr_mask != 0)
+        if ((chattr_mask & CHATTR_EARLY_FL) != 0)
                 (void) chattr_fd(fdt, chattr_flags, chattr_mask & CHATTR_EARLY_FL);
 
         r = copy_file_fd_at_full(dir_fdf, from, fdt, copy_flags, progress_bytes, userdata);
@@ -1593,7 +1593,7 @@ int copy_file_atomic_at_full(
         t = mfree(t);
 
         unsigned nocow = FLAGS_SET(copy_flags, COPY_NOCOW_AFTER) ? FS_NOCOW_FL : 0;
-        if ((chattr_mask | nocow) != 0)
+        if (((chattr_mask & ~CHATTR_EARLY_FL) | nocow) != 0)
                 (void) chattr_fd(fdt, chattr_flags | nocow, (chattr_mask & ~CHATTR_EARLY_FL) | nocow);
 
         r = close_nointr(TAKE_FD(fdt)); /* even if this fails, the fd is now invalidated */