]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
copy: add copy_access() helper for copying access mode
authorLennart Poettering <lennart@poettering.net>
Tue, 28 Jul 2020 21:38:23 +0000 (23:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 11 Aug 2020 20:26:48 +0000 (22:26 +0200)
src/basic/copy.c
src/basic/copy.h

index b384010ae321d1a74ef09ae368977ac595a1e4d6..54f7235b16c265eedd070d8aed4df219cd22a9b3 100644 (file)
@@ -969,6 +969,21 @@ int copy_times(int fdf, int fdt, CopyFlags flags) {
         return 0;
 }
 
+int copy_access(int fdf, int fdt) {
+        struct stat st;
+
+        assert(fdf >= 0);
+        assert(fdt >= 0);
+
+        if (fstat(fdf, &st) < 0)
+                return -errno;
+
+        if (fchmod(fdt, st.st_mode & 07777) < 0)
+                return -errno;
+
+        return 0;
+}
+
 int copy_xattr(int fdf, int fdt) {
         _cleanup_free_ char *names = NULL;
         int ret = 0, r;
index af8e88af04815546a11ec2ad62cd7cfed4bf95aa..ab9031038ec85a850c0fab5a3846fab826970184 100644 (file)
@@ -61,4 +61,5 @@ static inline int copy_bytes(int fdf, int fdt, uint64_t max_bytes, CopyFlags cop
 }
 
 int copy_times(int fdf, int fdt, CopyFlags flags);
+int copy_access(int fdf, int fdt);
 int copy_xattr(int fdf, int fdt);