X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fcopy.c;h=9e4c3b0f72834ff44e3c6a418bfbf0e0a801944c;hb=4034a06ddb82ec9868cd52496fef2f5faa25575f;hp=3df636704c3ba9a333bb440d00cc2948eec48e39;hpb=ebd93cb684806ac0f352139e69ac8f53eb49f5e4;p=elogind.git diff --git a/src/shared/copy.c b/src/shared/copy.c index 3df636704..9e4c3b0f7 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -285,7 +285,7 @@ static int fd_copy_directory( else if (S_ISBLK(buf.st_mode) || S_ISCHR(buf.st_mode)) q = fd_copy_node(dirfd(d), de->d_name, &buf, fdt, de->d_name); else - q = -ENOTSUP; + q = -EOPNOTSUPP; if (q == -EEXIST && merge) q = 0; @@ -317,7 +317,7 @@ int copy_tree_at(int fdf, const char *from, int fdt, const char *to, bool merge) else if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode)) return fd_copy_node(fdf, from, &st, fdt, to); else - return -ENOTSUP; + return -EOPNOTSUPP; } int copy_tree(const char *from, const char *to, bool merge) { @@ -359,7 +359,7 @@ int copy_file_fd(const char *from, int fdt, bool try_reflink) { return r; } -int copy_file(const char *from, const char *to, int flags, mode_t mode) { +int copy_file(const char *from, const char *to, int flags, mode_t mode, unsigned chattr_flags) { int fdt, r; assert(from); @@ -371,6 +371,9 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode) { return -errno; } + if (chattr_flags != 0) + (void) chattr_fd(fdt, true, chattr_flags); + r = copy_file_fd(from, fdt, true); if (r < 0) { close(fdt); @@ -386,7 +389,7 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode) { return 0; } -int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace) { +int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace, unsigned chattr_flags) { _cleanup_free_ char *t; int r; @@ -397,13 +400,19 @@ int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace if (r < 0) return r; - r = copy_file(from, t, O_NOFOLLOW|O_EXCL, mode); + r = copy_file(from, t, O_NOFOLLOW|O_EXCL, mode, chattr_flags); if (r < 0) return r; - if (renameat2(AT_FDCWD, t, AT_FDCWD, to, replace ? 0 : RENAME_NOREPLACE) < 0) { - unlink_noerrno(t); - return -errno; + if (replace) { + r = renameat(AT_FDCWD, t, AT_FDCWD, to); + if (r < 0) + r = -errno; + } else + r = rename_noreplace(AT_FDCWD, t, AT_FDCWD, to); + if (r < 0) { + (void) unlink_noerrno(t); + return r; } return 0;