]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/mkdir: merge two if blocks, return more accurate errno
authorMike Yuan <me@yhndnzj.com>
Sat, 13 Jul 2024 16:54:36 +0000 (18:54 +0200)
committerMike Yuan <me@yhndnzj.com>
Sat, 13 Jul 2024 20:58:22 +0000 (22:58 +0200)
src/basic/mkdir.c
src/test/test-mkdir.c

index f87de0a2bf58b993bfb885f74b5e5a00c1778d45..3e1545a58bba3fad552a3a393fb536c87a970911 100644 (file)
@@ -151,15 +151,13 @@ int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, ui
         if (prefix) {
                 p = path_startswith_full(path, prefix, /* accept_dot_dot= */ false);
                 if (!p)
-                        return -ENOTDIR;
-        } else
-                p = path;
+                        return -EINVAL;
 
-        if (prefix) {
                 fd = open(prefix, O_PATH|O_DIRECTORY|O_CLOEXEC);
                 if (fd < 0)
                         return -errno;
-        }
+        } else
+                p = path;
 
         return mkdirat_parents_internal(fd, p, mode, uid, gid, flags, _mkdirat);
 }
index ef00729c08ba75470b6515f6740a42d266dbc916..b2cc910dd1382115128d0001ab338ff44eb38e4f 100644 (file)
@@ -75,7 +75,7 @@ TEST(mkdir_p_safe) {
         assert_se(is_dir(q, false) > 0);
         assert_se(is_dir(q, true) > 0);
 
-        assert_se(mkdir_p_safe(tmp, "/tmp/test-mkdir-outside", 0755, UID_INVALID, GID_INVALID, 0) == -ENOTDIR);
+        ASSERT_ERROR(mkdir_p_safe(tmp, "/tmp/test-mkdir-outside", 0755, UID_INVALID, GID_INVALID, 0), EINVAL);
 
         p = mfree(p);
         assert_se(p = path_join(tmp, "zero-mode/should-fail-to-create-child"));