From a23f6f4afb0f819c6c478975df41e235e8d0953a Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Tue, 14 Apr 2009 18:48:02 +0300 Subject: 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. --- src/del.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/del.c') diff --git a/src/del.c b/src/del.c index 3e480a9..e980d71 100644 --- a/src/del.c +++ b/src/del.c @@ -11,12 +11,15 @@ #include #include "apk_applet.h" +#include "apk_state.h" #include "apk_database.h" static int del_main(void *ctx, int argc, char **argv) { struct apk_database db; - int i, j; + struct apk_state *state; + struct apk_name *name; + int i, j, r; if (apk_db_open(&db, apk_root, APK_OPENF_WRITE) < 0) return -1; @@ -24,7 +27,13 @@ static int del_main(void *ctx, int argc, char **argv) if (db.world == NULL) goto out; + state = apk_state_new(&db); for (i = 0; i < argc; i++) { + struct apk_dependency dep; + + name = apk_db_get_name(&db, APK_BLOB_STR(argv[i])); + + /* Remove from world, so we get proper changeset */ for (j = 0; j < db.world->num; j++) { if (strcmp(db.world->item[j].name->name, argv[i]) == 0) { @@ -34,13 +43,26 @@ static int del_main(void *ctx, int argc, char **argv) apk_dependency_array_resize(db.world, db.world->num-1); } } - } + name->flags &= ~APK_NAME_TOPLEVEL; - apk_db_recalculate_and_commit(&db); + dep = (struct apk_dependency) { + .name = name, + .result_mask = APK_DEPMASK_CONFLICT, + }; + + r = apk_state_lock_dependency(state, &dep); + if (r != 0) { + apk_error("Unable to remove '%s'", name->name); + goto err; + } + } + r = apk_state_commit(state, &db); +err: + apk_state_unref(state); out: apk_db_close(&db); - return 0; + return r; } static struct apk_applet apk_del = { -- cgit v1.2.3-60-g2f50