summaryrefslogtreecommitdiff
path: root/src/add.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-04-14 18:48:02 +0300
committerTimo Teras <timo.teras@iki.fi>2009-04-14 18:48:02 +0300
commita23f6f4afb0f819c6c478975df41e235e8d0953a (patch)
tree41e30626def437dc13ecea54afbb2cb6765f5d37 /src/add.c
parent7cef96c30d2f2d585aa2edd7b6ab22e9e007cddc (diff)
downloadapk-tools-a23f6f4afb0f819c6c478975df41e235e8d0953a.tar.gz
apk-tools-a23f6f4afb0f819c6c478975df41e235e8d0953a.tar.bz2
apk-tools-a23f6f4afb0f819c6c478975df41e235e8d0953a.tar.xz
apk-tools-a23f6f4afb0f819c6c478975df41e235e8d0953a.zip
state: rework changeset calculation algorithm
Calculate changesets directly by stabilizating the package graph instead of recalculating the whole graph and then diffing (similar approach as seen in 'smart' package manager). The algorithm is not complete: defferred search space forking is missing. So you don't always get a solution on complex graphs. Benefits: - usually the search state tree is smaller (less memory used) - speed relational to changeset size, not database size (usually faster) - touch only packages related to users request (can work on partitially broken state; upgrades only necessary packages, fixes #7) Also implemented: - command prompt to confirm operation if packages are deleted or downgraded - requesting deletion of package suggests removal of all packages depending on the package being removed (you'll get list of packages that also get removed if you want package X removed) - option --simulate to see what would have been done (mainly for testing) - an untested implementation of versioned dependencies and conflicts A lot has changed, so expect new bugs too.
Diffstat (limited to 'src/add.c')
-rw-r--r--src/add.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/add.c b/src/add.c
index 7aa0b23..77abc3b 100644
--- a/src/add.c
+++ b/src/add.c
@@ -13,6 +13,7 @@
#include <stdio.h>
#include "apk_applet.h"
#include "apk_database.h"
+#include "apk_state.h"
struct add_ctx {
unsigned int open_flags;
@@ -27,7 +28,7 @@ static int add_parse(void *ctx, int optch, int optindex, const char *optarg)
actx->open_flags |= APK_OPENF_CREATE;
break;
case 'u':
- apk_upgrade = 1;
+ apk_flags |= APK_UPGRADE;
break;
default:
return -1;
@@ -39,12 +40,14 @@ static int add_main(void *ctx, int argc, char **argv)
{
struct add_ctx *actx = (struct add_ctx *) ctx;
struct apk_database db;
- int i, r, ret = 1;
+ struct apk_state *state;
+ int i, r;
r = apk_db_open(&db, apk_root, actx->open_flags | APK_OPENF_WRITE);
if (r != 0)
return r;
+ state = apk_state_new(&db);
for (i = 0; i < argc; i++) {
struct apk_dependency dep;
@@ -59,20 +62,29 @@ static int add_main(void *ctx, int argc, char **argv)
dep = (struct apk_dependency) {
.name = pkg->name,
- .min_version = pkg->version,
- .max_version = pkg->version,
+ .version = pkg->version,
+ .result_mask = APK_VERSION_EQUAL,
};
} else {
dep = (struct apk_dependency) {
.name = apk_db_get_name(&db, APK_BLOB_STR(argv[i])),
+ .result_mask = APK_DEPMASK_REQUIRE,
};
}
apk_deps_add(&db.world, &dep);
+ dep.name->flags |= APK_NAME_TOPLEVEL;
+
+ r = apk_state_lock_dependency(state, &dep);
+ if (r != 0) {
+ apk_error("Unable to install '%s'", dep.name->name);
+ goto err;
+ }
}
- ret = apk_db_recalculate_and_commit(&db);
+ r = apk_state_commit(state, &db);
err:
+ apk_state_unref(state);
apk_db_close(&db);
- return ret;
+ return r;
}
static struct option add_options[] = {