summaryrefslogtreecommitdiff
path: root/src/shared/copy.c
diff options
context:
space:
mode:
authorAlban Crequy <alban@endocode.com>2015-03-10 18:15:52 +0100
committerLennart Poettering <lennart@poettering.net>2015-03-10 18:23:46 +0100
commitf85ef957e647c5182acf5e64298f68e4b7fbfe8f (patch)
tree505151f058adc41e72d262d044cc2b0092a148aa /src/shared/copy.c
parent27cc6f166bdebc0e698fb692993b801db2618866 (diff)
util: add rename_noreplace
renameat2() exists since Linux 3.15 but btrfs support for the flag RENAME_NOREPLACE was added later. This patch implements a fallback when renameat2() returns EINVAL. EINVAL is the error returned when the filesystem does not support one of the flags.
Diffstat (limited to 'src/shared/copy.c')
-rw-r--r--src/shared/copy.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/shared/copy.c b/src/shared/copy.c
index 0239a58066..f9ec6733be 100644
--- a/src/shared/copy.c
+++ b/src/shared/copy.c
@@ -404,9 +404,15 @@ int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace
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;