tree-wide: use _contains() rather than _get()/_find()
This commit is contained in:
@@ -33,7 +33,7 @@ static int list_remove_orphaned_file(
|
||||
if (event != RECURSE_DIR_ENTRY)
|
||||
return RECURSE_DIR_CONTINUE;
|
||||
|
||||
if (hashmap_get(known_files, path))
|
||||
if (hashmap_contains(known_files, path))
|
||||
return RECURSE_DIR_CONTINUE; /* keep! */
|
||||
|
||||
if (arg_dry_run)
|
||||
|
||||
@@ -2401,7 +2401,7 @@ static int object_added_append_all_prefix(
|
||||
* skip it on any of its parents. The child vtables
|
||||
* always fully override any conflicting vtables of
|
||||
* any parent node. */
|
||||
if (ordered_set_get(s, c->interface))
|
||||
if (ordered_set_contains(s, c->interface))
|
||||
continue;
|
||||
|
||||
r = ordered_set_put(s, c->interface);
|
||||
@@ -2616,7 +2616,7 @@ static int object_removed_append_all_prefix(
|
||||
* skip it on any of its parents. The child vtables
|
||||
* always fully override any conflicting vtables of
|
||||
* any parent node. */
|
||||
if (ordered_set_get(s, c->interface))
|
||||
if (ordered_set_contains(s, c->interface))
|
||||
continue;
|
||||
|
||||
r = node_vtable_get_userdata(bus, path, c, &u, &error);
|
||||
|
||||
@@ -3880,7 +3880,7 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error
|
||||
if (asprintf(&id, "%" PRIu64, ++m->inhibit_counter) < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
} while (hashmap_get(m->inhibitors, id));
|
||||
} while (hashmap_contains(m->inhibitors, id));
|
||||
|
||||
_cleanup_(inhibitor_freep) Inhibitor *i = NULL;
|
||||
r = manager_add_inhibitor(m, id, &i);
|
||||
|
||||
@@ -464,7 +464,7 @@ static int method_create_or_register_machine(
|
||||
supervisor_pidref = TAKE_PIDREF(client_pidref);
|
||||
}
|
||||
|
||||
if (hashmap_get(manager->machines, name))
|
||||
if (hashmap_contains(manager->machines, name))
|
||||
return sd_bus_error_setf(error, BUS_ERROR_MACHINE_EXISTS, "Machine '%s' already exists", name);
|
||||
|
||||
return machine_add_from_params(
|
||||
@@ -616,7 +616,7 @@ static int method_create_or_register_machine_ex(
|
||||
if (!isempty(root_directory) && (!path_is_absolute(root_directory) || !path_is_valid(root_directory)))
|
||||
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Root directory must be empty or an absolute path");
|
||||
|
||||
if (hashmap_get(manager->machines, name))
|
||||
if (hashmap_contains(manager->machines, name))
|
||||
return sd_bus_error_setf(error, BUS_ERROR_MACHINE_EXISTS, "Machine '%s' already exists", name);
|
||||
|
||||
/* If a PID is specified that's the leader, but if the client process is different from it, than that's the supervisor */
|
||||
|
||||
@@ -174,7 +174,7 @@ int vl_method_resolve_record(
|
||||
if (r == 0)
|
||||
break;
|
||||
|
||||
nxdomain = !!hashmap_get(m->machines, q);
|
||||
nxdomain = hashmap_contains(m->machines, q);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -869,7 +869,7 @@ static int link_put_carrier(Link *link, Link *carrier, Hashmap **h) {
|
||||
if (link == carrier)
|
||||
return 0;
|
||||
|
||||
if (hashmap_get(*h, INT_TO_PTR(carrier->ifindex)))
|
||||
if (hashmap_contains(*h, INT_TO_PTR(carrier->ifindex)))
|
||||
return 0;
|
||||
|
||||
r = hashmap_ensure_put(h, NULL, INT_TO_PTR(carrier->ifindex), carrier);
|
||||
|
||||
@@ -128,7 +128,7 @@ TEST(route_tables) {
|
||||
test_route_tables_one(manager, "bbb", 11111);
|
||||
test_route_tables_one(manager, "ccc", 22222);
|
||||
|
||||
ASSERT_NULL(hashmap_get(manager->route_table_numbers_by_name, "ddd"));
|
||||
ASSERT_FALSE(hashmap_contains(manager->route_table_numbers_by_name, "ddd"));
|
||||
|
||||
test_route_tables_one(manager, "default", 253);
|
||||
test_route_tables_one(manager, "main", 254);
|
||||
|
||||
@@ -381,7 +381,7 @@ static int extract_now(
|
||||
continue;
|
||||
|
||||
/* Filter out duplicates */
|
||||
if (hashmap_get(unit_files, de->d_name))
|
||||
if (hashmap_contains(unit_files, de->d_name))
|
||||
continue;
|
||||
|
||||
if (!IN_SET(de->d_type, DT_LNK, DT_REG))
|
||||
|
||||
@@ -92,7 +92,7 @@ TEST(parse_etc_hosts) {
|
||||
|
||||
/* See https://tools.ietf.org/html/rfc1035#section-2.3.1 */
|
||||
FOREACH_STRING(s, "bad-dash-", "-bad-dash", "-bad-dash.bad-")
|
||||
assert_se(!hashmap_get(hosts.by_name, s));
|
||||
ASSERT_FALSE(hashmap_contains(hosts.by_name, s));
|
||||
|
||||
assert_se(bn = hashmap_get(hosts.by_name, "before.comment"));
|
||||
assert_se(set_size(bn->addresses) == 4);
|
||||
@@ -101,17 +101,17 @@ TEST(parse_etc_hosts) {
|
||||
assert_se(has_4(bn->addresses, "1.2.3.11"));
|
||||
assert_se(has_4(bn->addresses, "1.2.3.12"));
|
||||
|
||||
assert_se(!hashmap_get(hosts.by_name, "within.comment"));
|
||||
assert_se(!hashmap_get(hosts.by_name, "within.comment2"));
|
||||
assert_se(!hashmap_get(hosts.by_name, "within.comment3"));
|
||||
assert_se(!hashmap_get(hosts.by_name, "#"));
|
||||
ASSERT_FALSE(hashmap_contains(hosts.by_name, "within.comment"));
|
||||
ASSERT_FALSE(hashmap_contains(hosts.by_name, "within.comment2"));
|
||||
ASSERT_FALSE(hashmap_contains(hosts.by_name, "within.comment3"));
|
||||
ASSERT_FALSE(hashmap_contains(hosts.by_name, "#"));
|
||||
|
||||
assert_se(!hashmap_get(hosts.by_name, "short.address"));
|
||||
assert_se(!hashmap_get(hosts.by_name, "long.address"));
|
||||
assert_se(!hashmap_get(hosts.by_name, "multi.colon"));
|
||||
assert_se(!set_contains(hosts.no_address, "short.address"));
|
||||
assert_se(!set_contains(hosts.no_address, "long.address"));
|
||||
assert_se(!set_contains(hosts.no_address, "multi.colon"));
|
||||
ASSERT_FALSE(hashmap_contains(hosts.by_name, "short.address"));
|
||||
ASSERT_FALSE(hashmap_contains(hosts.by_name, "long.address"));
|
||||
ASSERT_FALSE(hashmap_contains(hosts.by_name, "multi.colon"));
|
||||
ASSERT_FALSE(set_contains(hosts.no_address, "short.address"));
|
||||
ASSERT_FALSE(set_contains(hosts.no_address, "long.address"));
|
||||
ASSERT_FALSE(set_contains(hosts.no_address, "multi.colon"));
|
||||
|
||||
assert_se(bn = hashmap_get(hosts.by_name, "some.other"));
|
||||
assert_se(set_size(bn->addresses) == 1);
|
||||
|
||||
@@ -3499,7 +3499,7 @@ static int pattern_match_multiple_instances(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (strv_find(rule.instances, instance_name))
|
||||
if (strv_contains(rule.instances, instance_name))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -42,7 +42,7 @@ int web_cache_add_item(
|
||||
if (item && memcmp_nn(item->data, item->size, data, size) == 0)
|
||||
return 0;
|
||||
|
||||
if (hashmap_size(*web_cache) >= (size_t) (WEB_CACHE_ENTRIES_MAX + !!hashmap_get(*web_cache, url)))
|
||||
if (hashmap_size(*web_cache) >= (size_t) (WEB_CACHE_ENTRIES_MAX + hashmap_contains(*web_cache, url)))
|
||||
return -ENOSPC;
|
||||
|
||||
r = hashmap_ensure_allocated(web_cache, &web_cache_hash_ops);
|
||||
|
||||
@@ -1053,7 +1053,7 @@ static int uid_is_ok(
|
||||
assert(c);
|
||||
|
||||
/* Let's see if we already have assigned the UID a second time */
|
||||
if (ordered_hashmap_get(c->todo_uids, UID_TO_PTR(uid)))
|
||||
if (ordered_hashmap_contains(c->todo_uids, UID_TO_PTR(uid)))
|
||||
return 0;
|
||||
|
||||
/* Try to avoid using uids that are already used by a group
|
||||
@@ -1292,7 +1292,7 @@ static int gid_is_ok(
|
||||
assert(c);
|
||||
assert(groupname);
|
||||
|
||||
if (ordered_hashmap_get(c->todo_gids, GID_TO_PTR(gid)))
|
||||
if (ordered_hashmap_contains(c->todo_gids, GID_TO_PTR(gid)))
|
||||
return 0;
|
||||
|
||||
/* Avoid reusing gids that are already used by a different user */
|
||||
@@ -1568,7 +1568,7 @@ static int add_implicit(Context *c) {
|
||||
/* Implicitly create additional users and groups, if they were listed in "m" lines */
|
||||
ORDERED_HASHMAP_FOREACH_KEY(l, g, c->members) {
|
||||
STRV_FOREACH(m, l)
|
||||
if (!ordered_hashmap_get(c->users, *m)) {
|
||||
if (!ordered_hashmap_contains(c->users, *m)) {
|
||||
_cleanup_(item_freep) Item *j =
|
||||
item_new(ADD_USER, *m, /* filename= */ NULL, /* line= */ 0);
|
||||
if (!j)
|
||||
@@ -1584,8 +1584,8 @@ static int add_implicit(Context *c) {
|
||||
TAKE_PTR(j);
|
||||
}
|
||||
|
||||
if (!(ordered_hashmap_get(c->users, g) ||
|
||||
ordered_hashmap_get(c->groups, g))) {
|
||||
if (!(ordered_hashmap_contains(c->users, g) ||
|
||||
ordered_hashmap_contains(c->groups, g))) {
|
||||
_cleanup_(item_freep) Item *j =
|
||||
item_new(ADD_GROUP, g, /* filename= */ NULL, /* line= */ 0);
|
||||
if (!j)
|
||||
|
||||
+16
-16
@@ -184,32 +184,32 @@ int main(int argc, char *argv[]) {
|
||||
assert_se(manager_add_job(m, JOB_START, a_conj, JOB_REPLACE, NULL, &j) == -EDEADLK);
|
||||
manager_dump_jobs(m, stdout, /* patterns= */ NULL, "\t");
|
||||
|
||||
assert_se(!hashmap_get(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), b));
|
||||
assert_se(!hashmap_get(unit_get_dependencies(b, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
assert_se(!hashmap_get(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), c));
|
||||
assert_se(!hashmap_get(unit_get_dependencies(c, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
ASSERT_FALSE(hashmap_contains(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), b));
|
||||
ASSERT_FALSE(hashmap_contains(unit_get_dependencies(b, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
ASSERT_FALSE(hashmap_contains(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), c));
|
||||
ASSERT_FALSE(hashmap_contains(unit_get_dependencies(c, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
|
||||
assert_se(unit_add_dependency(a, UNIT_PROPAGATES_RELOAD_TO, b, true, UNIT_DEPENDENCY_UDEV) >= 0);
|
||||
assert_se(unit_add_dependency(a, UNIT_PROPAGATES_RELOAD_TO, c, true, UNIT_DEPENDENCY_PROC_SWAP) >= 0);
|
||||
|
||||
assert_se( hashmap_get(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), b));
|
||||
assert_se( hashmap_get(unit_get_dependencies(b, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
assert_se( hashmap_get(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), c));
|
||||
assert_se( hashmap_get(unit_get_dependencies(c, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
ASSERT_TRUE(hashmap_contains(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), b));
|
||||
ASSERT_TRUE(hashmap_contains(unit_get_dependencies(b, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
ASSERT_TRUE(hashmap_contains(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), c));
|
||||
ASSERT_TRUE(hashmap_contains(unit_get_dependencies(c, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
|
||||
unit_remove_dependencies(a, UNIT_DEPENDENCY_UDEV);
|
||||
|
||||
assert_se(!hashmap_get(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), b));
|
||||
assert_se(!hashmap_get(unit_get_dependencies(b, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
assert_se( hashmap_get(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), c));
|
||||
assert_se( hashmap_get(unit_get_dependencies(c, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
ASSERT_FALSE(hashmap_contains(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), b));
|
||||
ASSERT_FALSE(hashmap_contains(unit_get_dependencies(b, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
ASSERT_TRUE(hashmap_contains(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), c));
|
||||
ASSERT_TRUE(hashmap_contains(unit_get_dependencies(c, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
|
||||
unit_remove_dependencies(a, UNIT_DEPENDENCY_PROC_SWAP);
|
||||
|
||||
assert_se(!hashmap_get(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), b));
|
||||
assert_se(!hashmap_get(unit_get_dependencies(b, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
assert_se(!hashmap_get(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), c));
|
||||
assert_se(!hashmap_get(unit_get_dependencies(c, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
ASSERT_FALSE(hashmap_contains(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), b));
|
||||
ASSERT_FALSE(hashmap_contains(unit_get_dependencies(b, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
ASSERT_FALSE(hashmap_contains(unit_get_dependencies(a, UNIT_PROPAGATES_RELOAD_TO), c));
|
||||
ASSERT_FALSE(hashmap_contains(unit_get_dependencies(c, UNIT_RELOAD_PROPAGATED_FROM), a));
|
||||
|
||||
assert_se(manager_load_unit(m, "unit-with-multiple-dashes.service", NULL, NULL, &unit_with_multiple_dashes) >= 0);
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ TEST(hashmap_remove1) {
|
||||
|
||||
r = hashmap_get(m, "key 2");
|
||||
ASSERT_STREQ(r, "val 2");
|
||||
assert_se(!hashmap_get(m, "key 1"));
|
||||
ASSERT_FALSE(hashmap_contains(m, "key 1"));
|
||||
}
|
||||
|
||||
TEST(hashmap_remove2) {
|
||||
@@ -295,7 +295,7 @@ TEST(hashmap_remove2) {
|
||||
|
||||
r = hashmap_get(m, key2);
|
||||
ASSERT_STREQ(r, val2);
|
||||
assert_se(!hashmap_get(m, key1));
|
||||
ASSERT_FALSE(hashmap_contains(m, key1));
|
||||
}
|
||||
|
||||
TEST(hashmap_remove_value) {
|
||||
@@ -322,14 +322,14 @@ TEST(hashmap_remove_value) {
|
||||
|
||||
r = hashmap_get(m, "key 2");
|
||||
ASSERT_STREQ(r, "val 2");
|
||||
assert_se(!hashmap_get(m, "key 1"));
|
||||
ASSERT_FALSE(hashmap_contains(m, "key 1"));
|
||||
|
||||
r = hashmap_remove_value(m, "key 2", val1);
|
||||
ASSERT_NULL(r);
|
||||
|
||||
r = hashmap_get(m, "key 2");
|
||||
ASSERT_STREQ(r, "val 2");
|
||||
assert_se(!hashmap_get(m, "key 1"));
|
||||
ASSERT_FALSE(hashmap_contains(m, "key 1"));
|
||||
}
|
||||
|
||||
TEST(hashmap_remove_and_put) {
|
||||
@@ -354,7 +354,7 @@ TEST(hashmap_remove_and_put) {
|
||||
|
||||
r = hashmap_get(m, "key 2");
|
||||
ASSERT_STREQ(r, "val 2");
|
||||
assert_se(!hashmap_get(m, "key 1"));
|
||||
ASSERT_FALSE(hashmap_contains(m, "key 1"));
|
||||
|
||||
valid = hashmap_put(m, "key 3", (void*) (const char *) "val 3");
|
||||
assert_se(valid == 1);
|
||||
@@ -388,7 +388,7 @@ TEST(hashmap_remove_and_replace) {
|
||||
|
||||
r = hashmap_get(m, key2);
|
||||
assert_se(r == key2);
|
||||
assert_se(!hashmap_get(m, key1));
|
||||
ASSERT_FALSE(hashmap_contains(m, key1));
|
||||
|
||||
valid = hashmap_put(m, key3, key3);
|
||||
assert_se(valid == 1);
|
||||
@@ -396,7 +396,7 @@ TEST(hashmap_remove_and_replace) {
|
||||
assert_se(valid == 0);
|
||||
r = hashmap_get(m, key2);
|
||||
assert_se(r == key2);
|
||||
assert_se(!hashmap_get(m, key3));
|
||||
ASSERT_FALSE(hashmap_contains(m, key3));
|
||||
|
||||
/* Repeat this test several times to increase the chance of hitting
|
||||
* the less likely case in hashmap_remove_and_replace where it
|
||||
@@ -410,7 +410,7 @@ TEST(hashmap_remove_and_replace) {
|
||||
UINT_TO_PTR(10*i + 2),
|
||||
UINT_TO_PTR(10*i + 2));
|
||||
assert_se(valid == 0);
|
||||
assert_se(!hashmap_get(m, UINT_TO_PTR(10*i + 1)));
|
||||
ASSERT_FALSE(hashmap_contains(m, UINT_TO_PTR(10*i + 1)));
|
||||
for (j = 2; j < 7; j++) {
|
||||
r = hashmap_get(m, UINT_TO_PTR(10*i + j));
|
||||
assert_se(r == UINT_TO_PTR(10*i + j));
|
||||
@@ -914,10 +914,10 @@ TEST(path_hashmap) {
|
||||
assert_se(hashmap_get(h, "/.///./foox//.//") == INT_TO_PTR(4));
|
||||
assert_se(hashmap_get(h, "/foox/") == INT_TO_PTR(4));
|
||||
assert_se(hashmap_get(h, "/foox") == INT_TO_PTR(4));
|
||||
assert_se(!hashmap_get(h, "foox"));
|
||||
ASSERT_FALSE(hashmap_contains(h, "foox"));
|
||||
assert_se(hashmap_get(h, "foo/bar/quux") == INT_TO_PTR(6));
|
||||
assert_se(hashmap_get(h, "foo////bar////quux/////") == INT_TO_PTR(6));
|
||||
assert_se(!hashmap_get(h, "/foo////bar////quux/////"));
|
||||
ASSERT_FALSE(hashmap_contains(h, "/foo////bar////quux/////"));
|
||||
assert_se(hashmap_get(h, "foo././//ba.r////.quux///.//.") == INT_TO_PTR(9));
|
||||
}
|
||||
|
||||
@@ -950,14 +950,14 @@ TEST(string_strv_hashmap) {
|
||||
ASSERT_TRUE(strv_equal(s, STRV_MAKE("BAR")));
|
||||
|
||||
string_strv_hashmap_remove(m, "foo", "BAR");
|
||||
ASSERT_NULL(hashmap_get(m, "foo"));
|
||||
ASSERT_FALSE(hashmap_contains(m, "foo"));
|
||||
|
||||
string_strv_hashmap_remove(m, "xxx", "BAR");
|
||||
ASSERT_NOT_NULL((s = hashmap_get(m, "xxx")));
|
||||
ASSERT_TRUE(strv_equal(s, STRV_MAKE("bar")));
|
||||
|
||||
string_strv_hashmap_remove(m, "xxx", "bar");
|
||||
ASSERT_NULL(hashmap_get(m, "xxx"));
|
||||
ASSERT_FALSE(hashmap_contains(m, "xxx"));
|
||||
|
||||
ASSERT_TRUE(hashmap_isempty(m));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user