path-util: introduce empty_to_root() and use it many places
This commit is contained in:
parent
54138a8de1
commit
945403e6ed
|
@ -164,3 +164,6 @@ static inline const char *skip_dev_prefix(const char *p) {
|
|||
}
|
||||
|
||||
bool empty_or_root(const char *root);
|
||||
static inline const char *empty_to_root(const char *path) {
|
||||
return isempty(path) ? "/" : path;
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ static void show_cg_info(const char *controller, const char *path) {
|
|||
if (cg_all_unified() == 0 && controller && !streq(controller, SYSTEMD_CGROUP_CONTROLLER))
|
||||
printf("Controller %s; ", controller);
|
||||
|
||||
printf("Control group %s:\n", isempty(path) ? "/" : path);
|
||||
printf("Control group %s:\n", empty_to_root(path));
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
|
|
@ -529,10 +529,6 @@ static int refresh(const char *root, Hashmap *a, Hashmap *b, unsigned iteration)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const char *empty_to_slash(const char *p) {
|
||||
return isempty(p) ? "/" : p;
|
||||
}
|
||||
|
||||
static int group_compare(const void*a, const void *b) {
|
||||
const Group *x = *(Group**)a, *y = *(Group**)b;
|
||||
|
||||
|
@ -542,9 +538,9 @@ static int group_compare(const void*a, const void *b) {
|
|||
* recursive summing is off, since that is actually
|
||||
* not accumulative for all children. */
|
||||
|
||||
if (path_startswith(empty_to_slash(y->path), empty_to_slash(x->path)))
|
||||
if (path_startswith(empty_to_root(y->path), empty_to_root(x->path)))
|
||||
return -1;
|
||||
if (path_startswith(empty_to_slash(x->path), empty_to_slash(y->path)))
|
||||
if (path_startswith(empty_to_root(x->path), empty_to_root(y->path)))
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -693,7 +689,7 @@ static void display(Hashmap *a) {
|
|||
|
||||
g = array[j];
|
||||
|
||||
path = empty_to_slash(g->path);
|
||||
path = empty_to_root(g->path);
|
||||
ellipsized = ellipsize(path, path_columns, 33);
|
||||
printf("%-*s", path_columns, ellipsized ?: path);
|
||||
|
||||
|
|
|
@ -931,7 +931,7 @@ static int property_get_cgroup(
|
|||
* other cases we report as-is. */
|
||||
|
||||
if (u->cgroup_path)
|
||||
t = isempty(u->cgroup_path) ? "/" : u->cgroup_path;
|
||||
t = empty_to_root(u->cgroup_path);
|
||||
|
||||
return sd_bus_message_append(reply, "s", t);
|
||||
}
|
||||
|
|
|
@ -777,7 +777,7 @@ static int bus_socket_inotify_setup(sd_bus *b) {
|
|||
if (IN_SET(errno, ENOENT, ELOOP))
|
||||
break; /* This component doesn't exist yet, or the path contains a cyclic symlink right now */
|
||||
|
||||
r = log_debug_errno(errno, "Failed to add inotify watch on %s: %m", isempty(prefix) ? "/" : prefix);
|
||||
r = log_debug_errno(errno, "Failed to add inotify watch on %s: %m", empty_to_root(prefix));
|
||||
goto fail;
|
||||
} else
|
||||
new_watches[n++] = wd;
|
||||
|
|
|
@ -96,7 +96,7 @@ static void test_unit_name_from_path_one(const char *path, const char *suffix, c
|
|||
_cleanup_free_ char *k = NULL;
|
||||
assert_se(unit_name_to_path(t, &k) == 0);
|
||||
puts(strna(k));
|
||||
assert_se(path_equal(k, isempty(path) ? "/" : path));
|
||||
assert_se(path_equal(k, empty_to_root(path)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ static void test_unit_name_from_path_instance_one(const char *pattern, const cha
|
|||
|
||||
assert_se(unit_name_to_instance(t, &k) > 0);
|
||||
assert_se(unit_name_path_unescape(k, &v) == 0);
|
||||
assert_se(path_equal(v, isempty(path) ? "/" : path));
|
||||
assert_se(path_equal(v, empty_to_root(path)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1502,7 +1502,7 @@ static int create_item(Item *i) {
|
|||
|
||||
if (IN_SET(i->type, CREATE_SUBVOLUME, CREATE_SUBVOLUME_INHERIT_QUOTA, CREATE_SUBVOLUME_NEW_QUOTA)) {
|
||||
|
||||
if (btrfs_is_subvol(isempty(arg_root) ? "/" : arg_root) <= 0)
|
||||
if (btrfs_is_subvol(empty_to_root(arg_root)) <= 0)
|
||||
|
||||
/* Don't create a subvolume unless the
|
||||
* root directory is one, too. We do
|
||||
|
|
Loading…
Reference in a new issue