summaryrefslogtreecommitdiff
path: root/src/del.c
diff options
context:
space:
mode:
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 = {