sd-path: rename the two functions

I think the two names were both pretty bad. They did not give a proper hint
what the difference between the two functions is, and sd_path_home sounds like
it is somehow related to /home or home directories or whatever, when in fact
both functions return the same set of paths as either a colon-delimited string
or a strv. "_strv" suffix is used by various functions in sd-bus, so let's
reuse that.

Those functions are not public yet, so let's rename.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-03-23 19:50:59 +01:00
parent d32014a5bb
commit 51327bcc74
7 changed files with 21 additions and 21 deletions

View File

@ -689,7 +689,7 @@ static int manager_setup_prefix(Manager *m) {
p = paths_user;
for (i = 0; i < _EXEC_DIRECTORY_TYPE_MAX; i++) {
r = sd_path_home(p[i].type, p[i].suffix, &m->prefix[i]);
r = sd_path_lookup(p[i].type, p[i].suffix, &m->prefix[i]);
if (r < 0)
return r;
}

View File

@ -20,7 +20,7 @@ static int environment_dirs(char ***ret) {
return -ENOMEM;
/* ~/.config/systemd/environment.d */
r = sd_path_home(SD_PATH_USER_CONFIGURATION, "environment.d", &c);
r = sd_path_lookup(SD_PATH_USER_CONFIGURATION, "environment.d", &c);
if (r < 0)
return r;

View File

@ -323,7 +323,7 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
return -EOPNOTSUPP;
}
_public_ int sd_path_home(uint64_t type, const char *suffix, char **path) {
_public_ int sd_path_lookup(uint64_t type, const char *suffix, char **path) {
_cleanup_free_ char *buffer = NULL;
const char *ret;
char *cc;
@ -343,7 +343,7 @@ _public_ int sd_path_home(uint64_t type, const char *suffix, char **path) {
_cleanup_strv_free_ char **l = NULL;
r = sd_path_search(type, suffix, &l);
r = sd_path_lookup_strv(type, suffix, &l);
if (r < 0)
return r;
@ -550,7 +550,7 @@ static int get_search(uint64_t type, char ***list) {
return -EOPNOTSUPP;
}
_public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) {
_public_ int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***paths) {
char **i, **j;
_cleanup_strv_free_ char **l = NULL, **n = NULL;
int r;
@ -569,7 +569,7 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) {
char *p;
r = sd_path_home(type, suffix, &p);
r = sd_path_lookup(type, suffix, &p);
if (r < 0)
return r;

View File

@ -68,7 +68,7 @@ static int list_homes(void) {
_cleanup_free_ char *p = NULL;
int q;
q = sd_path_home(i, arg_suffix, &p);
q = sd_path_lookup(i, arg_suffix, &p);
if (q == -ENXIO)
continue;
if (q < 0) {
@ -91,7 +91,7 @@ static int print_home(const char *n) {
if (streq(path_table[i], n)) {
_cleanup_free_ char *p = NULL;
r = sd_path_home(i, arg_suffix, &p);
r = sd_path_lookup(i, arg_suffix, &p);
if (r < 0)
return log_error_errno(r, "Failed to query %s: %m", n);

View File

@ -81,8 +81,8 @@ enum {
_SD_PATH_MAX,
};
int sd_path_home(uint64_t type, const char *suffix, char **path);
int sd_path_search(uint64_t type, const char *suffix, char ***paths);
int sd_path_lookup(uint64_t type, const char *suffix, char **path);
int sd_path_lookup_strv(uint64_t type, const char *suffix, char ***paths);
_SD_END_DECLARATIONS;

View File

@ -7,40 +7,40 @@
#include "strv.h"
#include "tests.h"
static void test_sd_path_home(void) {
static void test_sd_path_lookup(void) {
log_info("/* %s */", __func__);
for (uint64_t i = 0; i < _SD_PATH_MAX; i++) {
_cleanup_free_ char *t, *s;
assert_se(sd_path_home(i, NULL, &t) == 0);
assert_se(sd_path_lookup(i, NULL, &t) == 0);
assert_se(t);
log_info("%02"PRIu64": \"%s\"", i, t);
assert_se(sd_path_home(i, "suffix", &s) == 0);
assert_se(sd_path_lookup(i, "suffix", &s) == 0);
assert_se(s);
log_info("%02"PRIu64": \"%s\"", i, s);
assert_se(endswith(s, "/suffix"));
}
char *tt;
assert_se(sd_path_home(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
}
static void test_sd_path_search(void) {
static void test_sd_path_lookup_strv(void) {
log_info("/* %s */", __func__);
for (uint64_t i = 0; i < _SD_PATH_MAX; i++) {
_cleanup_strv_free_ char **t, **s;
char **item;
assert_se(sd_path_search(i, NULL, &t) == 0);
assert_se(sd_path_lookup_strv(i, NULL, &t) == 0);
assert_se(t);
log_info("%02"PRIu64":", i);
STRV_FOREACH(item, t)
log_debug(" %s", *item);
assert_se(sd_path_search(i, "suffix", &s) == 0);
assert_se(sd_path_lookup_strv(i, "suffix", &s) == 0);
assert_se(s);
log_info("%02"PRIu64":", i);
STRV_FOREACH(item, s) {
@ -50,12 +50,12 @@ static void test_sd_path_search(void) {
}
char *tt;
assert_se(sd_path_home(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
}
int main(void) {
test_setup_logging(LOG_DEBUG);
test_sd_path_home();
test_sd_path_search();
test_sd_path_lookup();
test_sd_path_lookup_strv();
}

View File

@ -244,7 +244,7 @@ static int specifier_directory(char specifier, const void *data, const void *use
i = PTR_TO_UINT(data);
assert(i < ELEMENTSOF(paths_system));
return sd_path_home(paths[i].type, paths[i].suffix, ret);
return sd_path_lookup(paths[i].type, paths[i].suffix, ret);
}
static int log_unresolvable_specifier(const char *filename, unsigned line) {