fs-util: propagate EEXIST error in symlink_idempotent() as EEXIST

We really shouldn't silently translate the error code here for no
reason.
This commit is contained in:
Lennart Poettering 2017-09-26 18:26:20 +02:00
parent dab9698e1d
commit 77b79723a6
1 changed files with 7 additions and 4 deletions

View File

@ -359,22 +359,25 @@ int touch(const char *path) {
}
int symlink_idempotent(const char *from, const char *to) {
_cleanup_free_ char *p = NULL;
int r;
assert(from);
assert(to);
if (symlink(from, to) < 0) {
_cleanup_free_ char *p = NULL;
if (errno != EEXIST)
return -errno;
r = readlink_malloc(to, &p);
if (r < 0)
if (r == -EINVAL) /* Not a symlink? In that case return the original error we encountered: -EEXIST */
return -EEXIST;
if (r < 0) /* Any other error? In that case propagate it as is */
return r;
if (!streq(p, from))
return -EINVAL;
if (!streq(p, from)) /* Not the symlink we want it to be? In that case, propagate the original -EEXIST */
return -EEXIST;
}
return 0;