summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-08-13 16:02:02 +0300
committerTimo Teras <timo.teras@iki.fi>2009-08-13 16:02:02 +0300
commit892395d5947a0ebb04130df0f92cd107fba44d6d (patch)
treeefb2dd64ef326968fa851b928acaadd9c576c6ca /src
parent6b94ed8a7ac353298c4bb7ab1f247b1b1584784e (diff)
downloadapk-tools-892395d5947a0ebb04130df0f92cd107fba44d6d.tar.gz
apk-tools-892395d5947a0ebb04130df0f92cd107fba44d6d.tar.bz2
apk-tools-892395d5947a0ebb04130df0f92cd107fba44d6d.tar.xz
apk-tools-892395d5947a0ebb04130df0f92cd107fba44d6d.zip
add: refuse to add bad dependencies to world
allow also overriding old (possibly bad) world dependency. hopefully it's more bullet proof now.
Diffstat (limited to 'src')
-rw-r--r--src/add.c40
-rw-r--r--src/apk_database.h5
-rw-r--r--src/state.c3
3 files changed, 26 insertions, 22 deletions
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];