path-util: get rid of prefix_root()

prefix_root() is equivalent to path_join() in almost all ways, hence
let's remove it.

There are subtle differences though: prefix_root() will try shorten
multiple "/" before and after the prefix. path_join() doesn't do that.
This means prefix_root() might return a string shorter than both its
inputs combined, while path_join() never does that. I like the
path_join() semantics better, hence I think dropping prefix_root() is
totally OK. In the end the strings generated by both functon should
always be identical in terms of path_equal() if not streq().

This leaves prefix_roota() in place. Ideally we'd have path_joina(), but
I don't think we can reasonably implement that as a macro. or maybe we
can? (if so, sounds like something for a later PR)

Also add in a few missing OOM checks
This commit is contained in:
Lennart Poettering
2019-06-21 08:42:55 +09:00
committed by Yu Watanabe
parent f66ad46066
commit c6134d3e2f
14 changed files with 44 additions and 76 deletions
+2 -2
View File
@@ -36,7 +36,7 @@ int dev_setup(const char *prefix, uid_t uid, gid_t gid) {
}
if (prefix) {
link_name = prefix_root(prefix, k);
link_name = path_join(prefix, k);
if (!link_name)
return -ENOMEM;
@@ -91,7 +91,7 @@ int make_inaccessible_nodes(const char *root, uid_t uid, gid_t gid) {
for (i = 0; i < ELEMENTSOF(table); i++) {
_cleanup_free_ char *path = NULL;
path = prefix_root(root, table[i].name);
path = path_join(root, table[i].name);
if (!path)
return log_oom();