]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
chase: drop redundant call of delete_trailing_chars()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 10 Apr 2023 19:50:32 +0000 (04:50 +0900)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 11 Apr 2023 07:06:05 +0000 (09:06 +0200)
In that branch, 'root' is a non-root and absolute path.
Hence, delete_trailing_chars() does not make the path empty.
And, if the path contains redundant slashes at the end, that will be
dropped by path_simplify().

src/basic/chase.c

index f62c317026a61accccfd4419acdc18dd6190f991..e8d38279fdf44f28f47b87d22703af4de31a699c 100644 (file)
@@ -493,18 +493,19 @@ int chase(const char *path, const char *original_root, ChaseFlags flags, char **
                         return r;
 
                 /* Simplify the root directory, so that it has no duplicate slashes and nothing at the
-                 * end. While we won't resolve the root path we still simplify it. Note that dropping the
-                 * trailing slash should not change behaviour, since when opening it we specify O_DIRECTORY
-                 * anyway. Moreover at the end of this function after processing everything we'll always turn
-                 * the empty string back to "/". */
-                delete_trailing_chars(root, "/");
+                 * end. While we won't resolve the root path we still simplify it. */
                 path_simplify(root);
 
+                assert(path_is_absolute(root));
+                assert(!empty_or_root(root));
+
                 if (flags & CHASE_PREFIX_ROOT) {
                         absolute = path_join(root, path);
                         if (!absolute)
                                 return -ENOMEM;
                 }
+
+                flags |= CHASE_AT_RESOLVE_IN_ROOT;
         }
 
         if (!absolute) {
@@ -524,9 +525,6 @@ int chase(const char *path, const char *original_root, ChaseFlags flags, char **
         if (fd < 0)
                 return -errno;
 
-        if (!empty_or_root(root))
-                flags |= CHASE_AT_RESOLVE_IN_ROOT;
-
         r = chaseat(fd, path, flags & ~CHASE_PREFIX_ROOT, ret_path ? &p : NULL, ret_fd ? &pfd : NULL);
         if (r < 0)
                 return r;