shared/install: return bool where appropriate

This commit is contained in:
Mike Yuan
2024-05-01 15:00:29 +08:00
committed by Luca Boccassi
parent f9ef2aad28
commit 05adb256f1

View File

@@ -117,17 +117,23 @@ static int in_search_path(const LookupPaths *lp, const char *path) {
/* Check if 'path' is in lp->search_path. */
r = path_extract_directory(ASSERT_PTR(path), &parent);
assert(lp);
assert(path);
r = path_extract_directory(path, &parent);
if (r < 0)
return r;
return path_strv_contains(ASSERT_PTR(lp)->search_path, parent);
return path_strv_contains(lp->search_path, parent);
}
static int underneath_search_path(const LookupPaths *lp, const char *path) {
static bool underneath_search_path(const LookupPaths *lp, const char *path) {
/* Check if 'path' is underneath lp->search_path. */
return !!path_startswith_strv(ASSERT_PTR(path), ASSERT_PTR(lp)->search_path);
assert(lp);
assert(path);
return path_startswith_strv(path, lp->search_path);
}
static const char* skip_root(const char *root_dir, const char *path) {
@@ -2516,11 +2522,8 @@ int unit_file_link(
/* A silent noop if the file is already in the search path. */
continue;
r = underneath_search_path(&lp, *file);
if (r > 0)
r = -ETXTBSY;
if (r < 0)
return install_changes_add(changes, n_changes, r, *file, NULL);
if (underneath_search_path(&lp, *file))
return install_changes_add(changes, n_changes, -ETXTBSY, *file, NULL);
if (!GREEDY_REALLOC0(todo, n_todo + 2))
return -ENOMEM;