From 892395d5947a0ebb04130df0f92cd107fba44d6d Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Thu, 13 Aug 2009 16:02:02 +0300 Subject: add: refuse to add bad dependencies to world allow also overriding old (possibly bad) world dependency. hopefully it's more bullet proof now. --- src/add.c | 40 ++++++++++++++++++++-------------------- src/apk_database.h | 5 +++-- src/state.c | 3 +++ 3 files changed, 26 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/add.c b/src/add.c index f287b24..986e50c 100644 --- a/src/add.c +++ b/src/add.c @@ -56,15 +56,14 @@ static int non_repository_check(struct apk_database *db) return 1; } - static int add_main(void *ctx, struct apk_database *db, int argc, char **argv) { struct add_ctx *actx = (struct add_ctx *) ctx; struct apk_state *state = NULL; - struct apk_dependency_array *pkgs = NULL; struct apk_package *virtpkg = NULL; struct apk_dependency virtdep; - int i, r = 0; + struct apk_dependency *deps; + int i, r = 0, num_deps = 0; if (actx->virtpkg) { if (non_repository_check(db)) @@ -83,7 +82,11 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv) apk_dep_from_pkg(&virtdep, db, virtpkg); virtdep.name->flags |= APK_NAME_TOPLEVEL; virtpkg = apk_db_pkg_add(db, virtpkg); - } + num_deps = 1; + } else + num_deps = argc; + + deps = alloca(sizeof(struct apk_dependency) * num_deps); for (i = 0; i < argc; i++) { struct apk_dependency dep; @@ -111,29 +114,27 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv) goto err; } - if (virtpkg) { + if (virtpkg) apk_deps_add(&virtpkg->depends, &dep); - } else { - apk_deps_add(&db->world, &dep); - dep.name->flags |= APK_NAME_TOPLEVEL; - } - apk_deps_add(&pkgs, &dep); - } - - if (virtpkg) { - apk_deps_add(&pkgs, &virtdep); - apk_deps_add(&db->world, &virtdep); + else + deps[i] = dep; + deps[i].name->flags |= APK_NAME_TOPLEVEL_OVERRIDE; } + if (virtpkg) + deps[0] = virtdep; state = apk_state_new(db); if (state == NULL) goto err; - for (i = 0; (pkgs != NULL) && i < pkgs->num; i++) { - r = apk_state_lock_dependency(state, &pkgs->item[i]); - if (r != 0) { + for (i = 0; i < num_deps; i++) { + r = apk_state_lock_dependency(state, &deps[i]); + if (r == 0) { + apk_deps_add(&db->world, &deps[i]); + deps[i].name->flags |= APK_NAME_TOPLEVEL; + } else { apk_error("Unable to install '%s': %d", - pkgs->item[i].name->name, r); + deps[i].name->name, r); if (!(apk_flags & APK_FORCE)) goto err; } @@ -169,4 +170,3 @@ static struct apk_applet apk_add = { }; APK_DEFINE_APPLET(apk_add); - diff --git a/src/apk_database.h b/src/apk_database.h index dfaf0d3..c49eba8 100644 --- a/src/apk_database.h +++ b/src/apk_database.h @@ -64,8 +64,9 @@ struct apk_db_dir_instance { gid_t gid; }; -#define APK_NAME_TOPLEVEL 0x0001 -#define APK_NAME_REINSTALL 0x0002 +#define APK_NAME_TOPLEVEL 0x0001 +#define APK_NAME_REINSTALL 0x0002 +#define APK_NAME_TOPLEVEL_OVERRIDE 0x0004 struct apk_name { apk_hash_node hash_node; diff --git a/src/state.c b/src/state.c index 7a5ab73..3f00322 100644 --- a/src/state.c +++ b/src/state.c @@ -101,6 +101,9 @@ static struct apk_name_choices *name_choices_new(struct apk_database *db, memcpy(nc->pkgs, name->pkgs->item, name->pkgs->num * sizeof(struct apk_package *)); + if (name->flags & APK_NAME_TOPLEVEL_OVERRIDE) + return nc; + /* Check for global dependencies */ for (i = 0; db->world != NULL && i < db->world->num; i++) { struct apk_dependency *dep = &db->world->item[i]; -- cgit v1.2.3