summaryrefslogtreecommitdiff
path: root/src/del.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/del.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/del.c')
-rw-r--r--src/del.c30
1 files changed, 26 insertions, 4 deletions
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 <stdio.h>
#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 = {