]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/mkdir: simplify error handling
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 29 Mar 2023 14:00:03 +0000 (16:00 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 3 Apr 2023 13:28:00 +0000 (15:28 +0200)
If we created the dir successfully, we let chmod_and_chown_at() do its thing
and shouldn't go into the part where we check if the existing directory has the
right permissions and ownership and possibly adjust them. The code was doing
that, by relying on the fact that chmod_and_chown_at() does not return -EEXIST.
That's probably true, but seems unnecessarilly complicated.

Follow-up for c1b1492a94b43ca636eb383c3b058feff27ff7b1.

src/basic/mkdir.c

index 3b7cf7a0bf4c0d5b6f36378c77f9b7b54d8570ba..41af1482bc7bfbf0d139bcc4c913df485d6389ef 100644 (file)
@@ -33,11 +33,8 @@ int mkdirat_safe_internal(
         assert(_mkdirat && _mkdirat != mkdirat);
 
         r = _mkdirat(dir_fd, path, mode);
-        if (r >= 0) {
-                r = chmod_and_chown_at(dir_fd, path, mode, uid, gid);
-                if (r < 0)
-                        return r;
-        }
+        if (r >= 0)
+                return chmod_and_chown_at(dir_fd, path, mode, uid, gid);
         if (r != -EEXIST)
                 return r;