summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2016-07-22 11:13:33 +0300
committerTimo Teräs <timo.teras@iki.fi>2016-07-22 11:13:33 +0300
commitac0a9659d1c86e9c0b4234a16486e084bcb0a555 (patch)
tree6daddc204773eaf3007c672de53109278e3cf0b4 /src
parent22434a5ff03db80f329c90fc628f3332f87698d4 (diff)
downloadapk-tools-ac0a9659d1c86e9c0b4234a16486e084bcb0a555.tar.gz
apk-tools-ac0a9659d1c86e9c0b4234a16486e084bcb0a555.tar.bz2
apk-tools-ac0a9659d1c86e9c0b4234a16486e084bcb0a555.tar.xz
apk-tools-ac0a9659d1c86e9c0b4234a16486e084bcb0a555.zip
upgrade: improve self upgrade functionality a bit
trigger it only if apk-tools can be upgrade, add test cases
Diffstat (limited to 'src')
-rw-r--r--src/apk_database.h2
-rw-r--r--src/commit.c2
-rw-r--r--src/solver.c9
-rw-r--r--src/upgrade.c46
4 files changed, 45 insertions, 14 deletions
diff --git a/src/apk_database.h b/src/apk_database.h
index 158c7bb..28cff04 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -150,7 +150,7 @@ struct apk_database {
unsigned int local_repos, available_repos;
int repo_update_errors;
unsigned int pending_triggers;
- int performing_self_update : 1;
+ int performing_self_upgrade : 1;
int permanent : 1;
int open_complete : 1;
int compat_newfeatures : 1;
diff --git a/src/commit.c b/src/commit.c
index deb38de..b87311d 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -309,7 +309,7 @@ all_done:
apk_dependency_array_copy(&db->world, world);
apk_db_write_config(db);
- if (!db->performing_self_update) {
+ if (!db->performing_self_upgrade) {
if (errors)
snprintf(buf, sizeof(buf), "%d errors;", errors);
else
diff --git a/src/solver.c b/src/solver.c
index d287043..f41dffd 100644
--- a/src/solver.c
+++ b/src/solver.c
@@ -482,6 +482,7 @@ static int compare_providers(struct apk_solver_state *ss,
unsigned int solver_flags;
int r;
+
/* Prefer existing package */
if (pkgA == NULL || pkgB == NULL)
return (pkgA != NULL) - (pkgB != NULL);
@@ -521,7 +522,7 @@ static int compare_providers(struct apk_solver_state *ss,
return r;
/* Prefer installed on self-upgrade */
- if (db->performing_self_update && !(solver_flags & APK_SOLVERF_UPGRADE)) {
+ if (db->performing_self_upgrade && !(solver_flags & APK_SOLVERF_UPGRADE)) {
r = (pkgA->ipkg != NULL) - (pkgB->ipkg != NULL);
if (r)
return r;
@@ -631,8 +632,8 @@ static void select_package(struct apk_solver_state *ss, struct apk_name *name)
if (name->ss.requirers || name->ss.has_iif) {
foreach_array_item(p, name->providers) {
- dbg_printf(" consider "PKG_VER_FMT" iif_triggered=%d, tag_ok=%d\n",
- PKG_VER_PRINTF(p->pkg), p->pkg->ss.iif_triggered, p->pkg->ss.tag_ok);
+ dbg_printf(" consider "PKG_VER_FMT" iif_triggered=%d, tag_ok=%d, selectable=%d\n",
+ PKG_VER_PRINTF(p->pkg), p->pkg->ss.iif_triggered, p->pkg->ss.tag_ok, p->pkg->ss.pkg_selectable);
/* Ensure valid pinning and install-if trigger */
if (name->ss.requirers == 0 &&
(!p->pkg->ss.iif_triggered ||
@@ -979,7 +980,7 @@ restart:
pkg = name->ss.chosen.pkg;
if (pkg == NULL || pkg->ss.error) {
d->broken = 1;
- dbg_printf("disabling broken world dep: %s", name->name);
+ dbg_printf("disabling broken world dep: %s\n", name->name);
}
}
apk_hash_foreach(&db->available.names, free_name, NULL);
diff --git a/src/upgrade.c b/src/upgrade.c
index 1429aec..22839db 100644
--- a/src/upgrade.c
+++ b/src/upgrade.c
@@ -21,6 +21,7 @@
struct upgrade_ctx {
unsigned short solver_flags;
int no_self_upgrade : 1;
+ int self_upgrade_only : 1;
};
static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int optch, const char *optarg)
@@ -31,6 +32,9 @@ static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt
case 0x10000:
uctx->no_self_upgrade = 1;
break;
+ case 0x10001:
+ uctx->self_upgrade_only = 1;
+ break;
case 'a':
uctx->solver_flags |= APK_SOLVERF_AVAILABLE;
break;
@@ -54,6 +58,7 @@ static const struct apk_option options_applet[] = {
"print error if it cannot be installed due to other dependencies" },
{ 0x10000, "no-self-upgrade",
"Do not do early upgrade of 'apk-tools' package" },
+ { 0x10001, "self-upgrade-only", "Only do self-upgrade" },
};
static const struct apk_option_group optgroup_applet = {
@@ -63,32 +68,56 @@ static const struct apk_option_group optgroup_applet = {
.parse = option_parse_applet,
};
-int apk_do_self_upgrade(struct apk_database *db, unsigned short solver_flags)
+int apk_do_self_upgrade(struct apk_database *db, unsigned short solver_flags, unsigned int self_upgrade_only)
{
struct apk_name *name;
+ struct apk_package *pkg;
+ struct apk_provider *p0;
struct apk_changeset changeset = {};
int r;
name = apk_db_get_name(db, APK_BLOB_STR("apk-tools"));
+
+ /* First check if new version is even available */
+ r = 0;
+ pkg = apk_pkg_get_installed(name);
+ if (!pkg) goto ret;
+
+ foreach_array_item(p0, name->providers) {
+ struct apk_package *pkg0 = p0->pkg;
+ if (pkg0->name != name || pkg0->repos == 0)
+ continue;
+ if (apk_version_compare_blob(*pkg0->version, *pkg->version) == APK_VERSION_GREATER) {
+ r = 1;
+ break;
+ }
+ }
+
+ if (r == 0) goto ret;
+
+ /* Create new commit upgrading apk-tools only with minimal other changes */
+ db->performing_self_upgrade = 1;
apk_solver_set_name_flags(name, solver_flags, 0);
- db->performing_self_update = 1;
r = apk_solver_solve(db, 0, db->world, &changeset);
if (r != 0) {
- apk_solver_print_errors(db, &changeset, db->world);
+ apk_warning("Failed to perform initial self-upgrade, continuing with full upgrade.");
+ r = 0;
goto ret;
}
if (changeset.num_total_changes == 0)
goto ret;
- if (apk_flags & APK_SIMULATE) {
+ if (!self_upgrade_only && apk_flags & APK_SIMULATE) {
apk_warning("This simulation is not reliable as apk-tools upgrade is available.");
goto ret;
}
apk_message("Upgrading critical system libraries and apk-tools:");
apk_solver_commit_changeset(db, &changeset, db->world);
+ if (self_upgrade_only) goto ret;
+
apk_db_close(db);
apk_message("Continuing the upgrade transaction with new apk-tools:");
@@ -102,8 +131,7 @@ int apk_do_self_upgrade(struct apk_database *db, unsigned short solver_flags)
ret:
apk_change_array_free(&changeset.changes);
- db->performing_self_update = 0;
-
+ db->performing_self_upgrade = 0;
return r;
}
@@ -113,7 +141,7 @@ static int upgrade_main(void *ctx, struct apk_database *db, struct apk_string_ar
unsigned short solver_flags;
struct apk_dependency *dep;
struct apk_dependency_array *world = NULL;
- int r;
+ int r = 0;
if (apk_db_check_world(db, db->world) != 0) {
apk_error("Not continuing with upgrade due to missing repository tags. Use --force to override.");
@@ -122,10 +150,12 @@ static int upgrade_main(void *ctx, struct apk_database *db, struct apk_string_ar
solver_flags = APK_SOLVERF_UPGRADE | uctx->solver_flags;
if (!uctx->no_self_upgrade) {
- r = apk_do_self_upgrade(db, solver_flags);
+ r = apk_do_self_upgrade(db, solver_flags, uctx->self_upgrade_only);
if (r != 0)
return r;
}
+ if (uctx->self_upgrade_only)
+ return 0;
if (solver_flags & APK_SOLVERF_AVAILABLE) {
apk_dependency_array_copy(&world, db->world);