diff options
author | Timo Teräs <timo.teras@iki.fi> | 2011-01-01 15:48:10 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2011-01-01 15:48:10 +0200 |
commit | 59d222d58c003f4eb564edcc1d01c5b40690938c (patch) | |
tree | 1010fc6fff4e752dc7a0dfc468f61a80efe92b09 /src/upgrade.c | |
parent | 0cc41ba4dc47561f8a2299b985be777c2befdb74 (diff) | |
download | apk-tools-59d222d58c003f4eb564edcc1d01c5b40690938c.tar.gz apk-tools-59d222d58c003f4eb564edcc1d01c5b40690938c.tar.bz2 apk-tools-59d222d58c003f4eb564edcc1d01c5b40690938c.tar.xz apk-tools-59d222d58c003f4eb564edcc1d01c5b40690938c.zip |
upgrade: perform upgrade of apk-tools first if available
Also re-exec's apk-tools to perform rest of the upgrade using
the new apk-tools. This allows handling of new apk-tools features
properly. Fixes #140.
Diffstat (limited to 'src/upgrade.c')
-rw-r--r-- | src/upgrade.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/upgrade.c b/src/upgrade.c index be6a499..8763cb2 100644 --- a/src/upgrade.c +++ b/src/upgrade.c @@ -30,6 +30,46 @@ 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) +{ + struct apk_dependency dep; + int r, i; + + apk_dep_from_blob(&dep, db, APK_BLOB_STR("apk-tools")); + + if (apk_flags & APK_PREFER_AVAILABLE) { + for (i = 0; i < db->world->num; i++) { + struct apk_dependency *dep0 = &db->world->item[i]; + if (dep0->name != dep.name) + continue; + dep0->version = apk_blob_atomize(APK_BLOB_NULL); + dep0->result_mask = APK_VERSION_EQUAL | APK_VERSION_LESS | APK_VERSION_GREATER; + break; + } + } + + r = apk_state_lock_dependency(state, &dep); + if (r != 0 || state->num_changes == 0) + return r; + + if (apk_flags & APK_SIMULATE) { + apk_warning("This simulation is not reliable as apk-tools upgrade is available."); + return 0; + } + + apk_message("Uprading first to new apk-tools:"); + state->print_ok = 0; + r = apk_state_commit(state, db); + apk_state_unref(state); + apk_db_close(db); + + apk_message("Performing rest of the operation:"); + execvp(apk_argv[0], apk_argv); + + apk_error("PANIC! Failed to re-execute new apk-tools!"); + exit(1); +} + static int upgrade_main(void *ctx, struct apk_database *db, int argc, char **argv) { struct apk_state *state = NULL; @@ -38,12 +78,18 @@ static int upgrade_main(void *ctx, struct apk_database *db, int argc, char **arg int i, r = 0; apk_flags |= APK_UPGRADE; - apk_name_array_init(&missing); + state = apk_state_new(db); if (state == NULL) goto err; + r = apk_do_self_upgrade(db, state); + if (r != 0) { + apk_state_print_errors(state); + goto err; + } + for (i = 0; i < db->world->num; i++) { struct apk_dependency *dep = &db->world->item[i]; if (dep->version != null_atom && |