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.
This commit is contained in:
committed by
Lennart Poettering
parent
27cc6f166b
commit
f85ef957e6
@@ -440,8 +440,9 @@ int image_rename(Image *i, const char *new_name) {
|
||||
if (!nn)
|
||||
return -ENOMEM;
|
||||
|
||||
if (renameat2(AT_FDCWD, i->path, AT_FDCWD, new_path, RENAME_NOREPLACE) < 0)
|
||||
return -errno;
|
||||
r = rename_noreplace(AT_FDCWD, i->path, AT_FDCWD, new_path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
/* Restore the immutable bit, if it was set before */
|
||||
if (file_attr & FS_IMMUTABLE_FL)
|
||||
|
||||
Reference in New Issue
Block a user