]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkdir: reset mtime *after* fchown()
authorMike Yuan <me@yhndnzj.com>
Tue, 20 Jan 2026 17:54:25 +0000 (18:54 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Jan 2026 23:35:31 +0000 (08:35 +0900)
Follow-up for 34c3d574742e867ef97e79509e4051a82f1b7d9b

Also, drop pointless shortcut.

src/basic/mkdir.c

index f670840e3cecfb289b876bfeb1890df5c8dc4915..837880baa2ec21f0fd0b2b9c923ad138cee4f075 100644 (file)
@@ -255,8 +255,8 @@ int mkdir_p_root_full(const char *root, const char *p, uid_t uid, gid_t gid, mod
         if (nfd < 0)
                 return nfd;
 
-        if (ts == USEC_INFINITY && !uid_is_valid(uid) && !gid_is_valid(gid))
-                return 1;
+        if ((uid_is_valid(uid) || gid_is_valid(gid)) && fchown(nfd, uid, gid) < 0)
+                return -errno;
 
         if (ts != USEC_INFINITY) {
                 struct timespec tspec;
@@ -269,8 +269,5 @@ int mkdir_p_root_full(const char *root, const char *p, uid_t uid, gid_t gid, mod
                         return -errno;
         }
 
-        if ((uid_is_valid(uid) || gid_is_valid(gid)) && fchown(nfd, uid, gid) < 0)
-                return -errno;
-
         return 1;
 }