chiark / gitweb /
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)
committerSven Eden <yamakuzure@gmx.net>
Wed, 22 Nov 2017 07:25:10 +0000 (08:25 +0100)
We really shouldn't silently translate the error code here for no
reason.

src/basic/fs-util.c

index 00c3a4e1b5f6b60930eb2a9d91489a230d2b5293..33467c37941bbb3b611b256f5bbf51cb609f3f00 100644 (file)
@@ -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;