From: Lennart Poettering Date: Tue, 28 Jul 2020 21:38:23 +0000 (+0200) Subject: copy: add copy_access() helper for copying access mode X-Git-Tag: v247-rc1~431^2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bacf21e9e900f66da72b3f47b0de0e8fcb3c4e16;p=thirdparty%2Fsystemd.git copy: add copy_access() helper for copying access mode --- diff --git a/src/basic/copy.c b/src/basic/copy.c index b384010ae32..54f7235b16c 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -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; diff --git a/src/basic/copy.h b/src/basic/copy.h index af8e88af048..ab9031038ec 100644 --- a/src/basic/copy.h +++ b/src/basic/copy.h @@ -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);