summaryrefslogtreecommitdiff
path: root/src/upgrade.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-09-09 16:31:11 +0300
committerTimo Teräs <timo.teras@iki.fi>2011-09-09 16:32:31 +0300
commita5a7021658212748e9f787ce23181d3e099aba73 (patch)
tree459384995fc52f096007c3ed4d8d88ca865f998c /src/upgrade.c
parent0e24207c2e4fedb9c0656ed98bc37cd37df44d91 (diff)
downloadapk-tools-a5a7021658212748e9f787ce23181d3e099aba73.tar.gz
apk-tools-a5a7021658212748e9f787ce23181d3e099aba73.tar.bz2
apk-tools-a5a7021658212748e9f787ce23181d3e099aba73.tar.xz
apk-tools-a5a7021658212748e9f787ce23181d3e099aba73.zip
applets: start using solver code
still todo: - 'fix' is missing - 'del -R' does not work - 'upgrade' does not do self-upgrade first ... and a lot of testing.
Diffstat (limited to 'src/upgrade.c')
-rw-r--r--src/upgrade.c70
1 files changed, 22 insertions, 48 deletions
diff --git a/src/upgrade.c b/src/upgrade.c
index ec0dc91..5afccfd 100644
--- a/src/upgrade.c
+++ b/src/upgrade.c
@@ -14,15 +14,21 @@
#include <zlib.h>
#include "apk_applet.h"
#include "apk_database.h"
-#include "apk_state.h"
#include "apk_print.h"
+#include "apk_solver.h"
+
+struct upgrade_ctx {
+ unsigned short solver_flags;
+};
static int upgrade_parse(void *ctx, struct apk_db_options *dbopts,
int optch, int optindex, const char *optarg)
{
+ struct upgrade_ctx *uctx = (struct upgrade_ctx *) ctx;
+
switch (optch) {
case 'a':
- apk_flags |= APK_PREFER_AVAILABLE;
+ uctx->solver_flags |= APK_SOLVERF_AVAILABLE;
break;
default:
return -1;
@@ -30,8 +36,10 @@ static int upgrade_parse(void *ctx, struct apk_db_options *dbopts,
return 0;
}
-int apk_do_self_upgrade(struct apk_database *db, struct apk_state *state)
+int apk_do_self_upgrade(struct apk_database *db)
{
+#if 0
+ /* FIXME: Reimplement self-upgrade. */
struct apk_dependency dep;
int r;
@@ -57,58 +65,24 @@ int apk_do_self_upgrade(struct apk_database *db, struct apk_state *state)
apk_error("PANIC! Failed to re-execute new apk-tools!");
exit(1);
+#else
+ return 0;
+#endif
}
static int upgrade_main(void *ctx, struct apk_database *db, int argc, char **argv)
{
- struct apk_state *state = NULL;
- struct apk_name_array *missing;
- int i, r = 0;
-
- apk_flags |= APK_UPGRADE;
- apk_name_array_init(&missing);
-
- state = apk_state_new(db);
- if (state == NULL)
- goto err;
+ struct upgrade_ctx *uctx = (struct upgrade_ctx *) ctx;
+ unsigned short solver_flags;
+ int r;
- r = apk_do_self_upgrade(db, state);
- if (r != 0) {
- apk_state_print_errors(state);
- goto err;
- }
+ solver_flags = APK_SOLVERF_UPGRADE | uctx->solver_flags;
- for (i = 0; i < db->world->num; i++) {
- struct apk_dependency *dep = &db->world->item[i];
+ r = apk_do_self_upgrade(db);
+ if (r != 0)
+ return r;
- if (dep->name->pkgs->num != 0)
- r |= apk_state_lock_dependency(state, dep);
- else
- *apk_name_array_add(&missing) = dep->name;
- }
- if (r == 0) {
- for (i = 0; i < missing->num; i++) {
- struct apk_indent indent;
- struct apk_name *name = missing->item[i];
-
- if (i == 0) {
- apk_warning("The following package names no longer exists in repository:");
- indent.x = 0;
- indent.indent = 2;
- }
- apk_print_indented(&indent, APK_BLOB_STR(name->name));
- }
- if (i != 0)
- printf("\n");
-
- r = apk_state_commit(state);
- } else
- apk_state_print_errors(state);
-err:
- if (state != NULL)
- apk_state_unref(state);
- apk_name_array_free(&missing);
- return r;
+ return apk_solver_commit(db, solver_flags, db->world);
}
static struct apk_option upgrade_options[] = {