1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-19 14:04:03 +03:00

install: make InstallContext::{will_install,have_installed} OrderedHashmaps

It appears order may matter here. Use OrderedHashmaps to be safe.
This commit is contained in:
Michal Schmidt 2014-08-22 10:35:59 +02:00
parent dd0124f6cb
commit 9f03ee51a2

View File

@ -41,8 +41,8 @@
#include "special.h"
typedef struct {
Hashmap *will_install;
Hashmap *have_installed;
OrderedHashmap *will_install;
OrderedHashmap *have_installed;
} InstallContext;
static int in_search_path(const char *path, char **search) {
@ -844,16 +844,16 @@ static void install_info_free(InstallInfo *i) {
free(i);
}
static void install_info_hashmap_free(Hashmap *m) {
static void install_info_hashmap_free(OrderedHashmap *m) {
InstallInfo *i;
if (!m)
return;
while ((i = hashmap_steal_first(m)))
while ((i = ordered_hashmap_steal_first(m)))
install_info_free(i);
hashmap_free(m);
ordered_hashmap_free(m);
}
static void install_context_done(InstallContext *c) {
@ -881,11 +881,11 @@ static int install_info_add(
if (!unit_name_is_valid(name, TEMPLATE_VALID))
return -EINVAL;
if (hashmap_get(c->have_installed, name) ||
hashmap_get(c->will_install, name))
if (ordered_hashmap_get(c->have_installed, name) ||
ordered_hashmap_get(c->will_install, name))
return 0;
r = hashmap_ensure_allocated(&c->will_install, &string_hash_ops);
r = ordered_hashmap_ensure_allocated(&c->will_install, &string_hash_ops);
if (r < 0)
return r;
@ -907,7 +907,7 @@ static int install_info_add(
}
}
r = hashmap_put(c->will_install, i->name, i);
r = ordered_hashmap_put(c->will_install, i->name, i);
if (r < 0)
goto fail;
@ -1180,7 +1180,7 @@ static int unit_file_can_install(
if (r < 0)
return r;
assert_se(i = hashmap_first(c.will_install));
assert_se(i = ordered_hashmap_first(c.will_install));
r = unit_file_search(&c, i, paths, root_dir, allow_symlink, true);
@ -1401,13 +1401,13 @@ static int install_context_apply(
assert(paths);
assert(config_path);
while ((i = hashmap_first(c->will_install))) {
while ((i = ordered_hashmap_first(c->will_install))) {
q = hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
q = ordered_hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
if (q < 0)
return q;
assert_se(hashmap_move_one(c->have_installed, c->will_install, i->name) == 0);
assert_se(ordered_hashmap_move_one(c->have_installed, c->will_install, i->name) == 0);
q = unit_file_search(c, i, paths, root_dir, false, true);
if (q < 0) {
@ -1442,13 +1442,13 @@ static int install_context_mark_for_removal(
/* Marks all items for removal */
while ((i = hashmap_first(c->will_install))) {
while ((i = ordered_hashmap_first(c->will_install))) {
q = hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
q = ordered_hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
if (q < 0)
return q;
assert_se(hashmap_move_one(c->have_installed, c->will_install, i->name) == 0);
assert_se(ordered_hashmap_move_one(c->have_installed, c->will_install, i->name) == 0);
q = unit_file_search(c, i, paths, root_dir, false, true);
if (q == -ENOENT) {
@ -1544,12 +1544,12 @@ int unit_file_add_dependency(
return r;
}
while ((info = hashmap_first(c.will_install))) {
r = hashmap_ensure_allocated(&c.have_installed, &string_hash_ops);
while ((info = ordered_hashmap_first(c.will_install))) {
r = ordered_hashmap_ensure_allocated(&c.have_installed, &string_hash_ops);
if (r < 0)
return r;
assert_se(hashmap_move_one(c.have_installed, c.will_install, info->name) == 0);
assert_se(ordered_hashmap_move_one(c.have_installed, c.will_install, info->name) == 0);
r = unit_file_search(&c, info, &paths, root_dir, false, false);
if (r < 0)
@ -1720,7 +1720,7 @@ int unit_file_set_default(
if (r < 0)
return r;
assert_se(i = hashmap_first(c.will_install));
assert_se(i = ordered_hashmap_first(c.will_install));
r = unit_file_search(&c, i, &paths, root_dir, false, true);
if (r < 0)