state: do not look into world in state_new

instead enforce world dependencies when the package name
is first referenced upon.
cute-signatures
Timo Teras 2009-08-06 16:39:09 +03:00
parent f02f326238
commit bf7b80662d
2 changed files with 25 additions and 21 deletions

View File

@ -854,8 +854,6 @@ static int add_protected_path(void *ctx, apk_blob_t blob)
static int apk_db_create(struct apk_database *db) static int apk_db_create(struct apk_database *db)
{ {
apk_blob_t deps = APK_BLOB_STR("busybox alpine-baselayout "
"apk-tools alpine-conf");
int fd; int fd;
mkdirat(db->root_fd, "tmp", 01777); mkdirat(db->root_fd, "tmp", 01777);
@ -868,7 +866,6 @@ static int apk_db_create(struct apk_database *db)
fd = openat(db->root_fd, "var/lib/apk/world", O_CREAT|O_RDWR|O_TRUNC, 0644); fd = openat(db->root_fd, "var/lib/apk/world", O_CREAT|O_RDWR|O_TRUNC, 0644);
if (fd < 0) if (fd < 0)
return -errno; return -errno;
write(fd, deps.ptr, deps.len);
close(fd); close(fd);
return 0; return 0;

View File

@ -82,9 +82,11 @@ static struct apk_name_choices *ns_to_choices(apk_name_state_t name)
return (struct apk_name_choices *) name; return (struct apk_name_choices *) name;
} }
static struct apk_name_choices *name_choices_new(struct apk_name *name) static struct apk_name_choices *name_choices_new(struct apk_database *db,
struct apk_name *name)
{ {
struct apk_name_choices *nc; struct apk_name_choices *nc;
int i, j;
if (name->pkgs == NULL) if (name->pkgs == NULL)
return NULL; return NULL;
@ -98,6 +100,26 @@ static struct apk_name_choices *name_choices_new(struct apk_name *name)
nc->num = name->pkgs->num; nc->num = name->pkgs->num;
memcpy(nc->pkgs, name->pkgs->item, memcpy(nc->pkgs, name->pkgs->item,
name->pkgs->num * sizeof(struct apk_package *)); name->pkgs->num * sizeof(struct apk_package *));
/* Check for global dependencies */
for (i = 0; db->world != NULL && i < db->world->num; i++) {
struct apk_dependency *dep = &db->world->item[i];
if (dep->name != name)
continue;
for (j = 0; j < nc->num; ) {
if (apk_version_compare(nc->pkgs[j]->version, dep->version)
& dep->result_mask) {
j++;
} else {
nc->pkgs[i] = nc->pkgs[nc->num - 1];
nc->num--;
}
}
}
return nc; return nc;
} }
@ -136,7 +158,7 @@ static void ns_free(apk_name_state_t name)
struct apk_state *apk_state_new(struct apk_database *db) struct apk_state *apk_state_new(struct apk_database *db)
{ {
struct apk_state *state; struct apk_state *state;
int num_bytes, i, r; int num_bytes;
num_bytes = sizeof(struct apk_state) + db->name_id * sizeof(char *); num_bytes = sizeof(struct apk_state) + db->name_id * sizeof(char *);
state = (struct apk_state*) calloc(1, num_bytes); state = (struct apk_state*) calloc(1, num_bytes);
@ -145,22 +167,7 @@ struct apk_state *apk_state_new(struct apk_database *db)
state->db = db; state->db = db;
list_init(&state->change_list_head); list_init(&state->change_list_head);
/* Instantiate each 'name' target in world, and lockout incompatible
* choices */
for (i = 0; db->world != NULL && i < db->world->num; i++) {
r = apk_state_prune_dependency(state, &db->world->item[i]);
if (r < 0 && apk_verbosity && !(apk_flags & APK_FORCE)) {
apk_error("Top level dependencies for %s are "
"conflicting or unsatisfiable.",
db->world->item[i].name->name);
goto err;
}
}
return state; return state;
err:
free(state);
return NULL;
} }
struct apk_state *apk_state_dup(struct apk_state *state) struct apk_state *apk_state_dup(struct apk_state *state)
@ -217,7 +224,7 @@ int apk_state_prune_dependency(struct apk_state *state,
/* This name has not been visited yet. /* This name has not been visited yet.
* Construct list of candidates. */ * Construct list of candidates. */
state->name[name->id] = ns_from_choices(name_choices_new(name)); state->name[name->id] = ns_from_choices(name_choices_new(state->db, name));
} }
if (ns_locked(state->name[name->id])) { if (ns_locked(state->name[name->id])) {