]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: propagate EEXIST error in symlink_idempotent() as EEXIST
authorLennart Poettering <lennart@poettering.net>
Tue, 26 Sep 2017 16:26:20 +0000 (18:26 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 27 Sep 2017 15:52:42 +0000 (17:52 +0200)
We really shouldn't silently translate the error code here for no
reason.

src/basic/fs-util.c

index fdedeffb9aaabf09dc0583b3b18cae3b6e922713..af631710412dd8f76c48506fd653c3f5e8f46c78 100644 (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;