From 9b74c28b7c2329b86d92c504c3455c178ec14e87 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 26 Sep 2017 18:26:20 +0200 Subject: fs-util: propagate EEXIST error in symlink_idempotent() as EEXIST We really shouldn't silently translate the error code here for no reason. --- src/basic/fs-util.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/basic') diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 00c3a4e1b..33467c379 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -38,7 +38,6 @@ #include "mkdir.h" #include "parse-util.h" #include "path-util.h" -#include "process-util.h" #include "stat-util.h" #include "stdio-util.h" #include "string-util.h" @@ -367,22 +366,25 @@ int touch(const char *path) { #if 0 /// UNNEEDED by elogind 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; -- cgit v1.2.3