summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--test/selfupgrade.repo37
-rw-r--r--test/selfupgrade1.installed18
-rw-r--r--test/selfupgrade1.test10
-rw-r--r--test/selfupgrade2.installed12
-rw-r--r--test/selfupgrade2.test11
-rw-r--r--test/selfupgrade3.installed18
-rw-r--r--test/selfupgrade3.test7
-rw-r--r--test/selfupgrade4.test7
-rwxr-xr-xtest/solver.sh2
13 files changed, 166 insertions, 15 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);
diff --git a/test/selfupgrade.repo b/test/selfupgrade.repo
new file mode 100644
index 0000000..44a7ca2
--- /dev/null
+++ b/test/selfupgrade.repo
@@ -0,0 +1,37 @@
+C:Q1EyN512pAOBJWKMR89pp/C66o+OE=
+P:apk-tools
+V:1
+S:1
+I:1
+D:libcrypto
+
+C:Q1EyN534pAOBJWKMR89pp/CFFo+OF=
+P:apk-tools
+V:2
+S:1
+I:1
+D:libcrypto>=2
+
+C:Q1eVpk56fqZAukAXFYbgwt4xAEEEe=
+P:libcrypto
+V:1
+S:1
+I:1
+
+C:Q1eVpka78qZAukAXFYbgwt4xAEFFe=
+P:libcrypto
+V:2
+S:1
+I:1
+
+C:Q1EyN5A77AOBJWKMR89pp/CFFo+OE=
+P:application
+V:1
+S:1
+I:1
+
+C:Q1EyN5A55AOBJWKMR89pp/CFFF+OE=
+P:application
+V:2
+S:1
+I:1
diff --git a/test/selfupgrade1.installed b/test/selfupgrade1.installed
new file mode 100644
index 0000000..5a7b052
--- /dev/null
+++ b/test/selfupgrade1.installed
@@ -0,0 +1,18 @@
+C:Q1EyN512pAOBJWKMR89pp/C66o+OE=
+P:apk-tools
+V:1
+S:1
+I:1
+D:libcrypto
+
+C:Q1eVpk56fqZAukAXFYbgwt4xAEEEe=
+P:libcrypto
+V:1
+S:1
+I:1
+
+C:Q1EyN5A77AOBJWKMR89pp/CFFo+OE=
+P:application
+V:1
+S:1
+I:1
diff --git a/test/selfupgrade1.test b/test/selfupgrade1.test
new file mode 100644
index 0000000..8afa133
--- /dev/null
+++ b/test/selfupgrade1.test
@@ -0,0 +1,10 @@
+@ARGS
+--test-repo selfupgrade.repo
+--test-instdb selfupgrade1.installed
+--test-world "apk-tools application"
+--self-upgrade-only
+upgrade
+@EXPECT
+Upgrading critical system libraries and apk-tools:
+(1/2) Upgrading libcrypto (1 -> 2)
+(2/2) Upgrading apk-tools (1 -> 2)
diff --git a/test/selfupgrade2.installed b/test/selfupgrade2.installed
new file mode 100644
index 0000000..1b0d0c8
--- /dev/null
+++ b/test/selfupgrade2.installed
@@ -0,0 +1,12 @@
+C:Q1EyN534pAOBJWKMR89pp/CFFo+OF=
+P:apk-tools
+V:2
+S:1
+I:1
+D:libcrypto>=2
+
+C:Q1eVpka78qZAukAXFYbgwt4xAEFFe=
+P:libcrypto
+V:2
+S:1
+I:1
diff --git a/test/selfupgrade2.test b/test/selfupgrade2.test
new file mode 100644
index 0000000..f0ca054
--- /dev/null
+++ b/test/selfupgrade2.test
@@ -0,0 +1,11 @@
+@ARGS
+--test-repo selfupgrade.repo
+--test-instdb selfupgrade1.installed
+--test-world apk-tools
+--self-upgrade-only
+upgrade
+@EXPECT
+Upgrading critical system libraries and apk-tools:
+(1/3) Purging application (1)
+(2/3) Upgrading libcrypto (1 -> 2)
+(3/3) Upgrading apk-tools (1 -> 2)
diff --git a/test/selfupgrade3.installed b/test/selfupgrade3.installed
new file mode 100644
index 0000000..701d3de
--- /dev/null
+++ b/test/selfupgrade3.installed
@@ -0,0 +1,18 @@
+C:Q1EyN534pAOBJWKMR89pp/CFFo+OF=
+P:apk-tools
+V:2
+S:1
+I:1
+D:libcrypto>=2
+
+C:Q1eVpka78qZAukAXFYbgwt4xAEFFe=
+P:libcrypto
+V:2
+S:1
+I:1
+
+C:Q1EyN5A55AOBJWKMR89pp/CFFF+OE=
+P:application
+V:2
+S:1
+I:1
diff --git a/test/selfupgrade3.test b/test/selfupgrade3.test
new file mode 100644
index 0000000..ec266d9
--- /dev/null
+++ b/test/selfupgrade3.test
@@ -0,0 +1,7 @@
+@ARGS
+--test-repo selfupgrade.repo
+--test-instdb selfupgrade2.installed
+--test-world "apk-tools application"
+--self-upgrade-only
+upgrade
+@EXPECT
diff --git a/test/selfupgrade4.test b/test/selfupgrade4.test
new file mode 100644
index 0000000..1b941ef
--- /dev/null
+++ b/test/selfupgrade4.test
@@ -0,0 +1,7 @@
+@ARGS
+--test-repo selfupgrade.repo
+--test-instdb selfupgrade3.installed
+--test-world "apk-tools"
+--self-upgrade-only
+upgrade
+@EXPECT
diff --git a/test/solver.sh b/test/solver.sh
index 8c27d8f..bc230c6 100755
--- a/test/solver.sh
+++ b/test/solver.sh
@@ -4,7 +4,7 @@ get_block() {
awk '/^@'$1'/{p=1;next} /^@/{p=0} p{print}'
}
-APK_TEST=../src/apk-test
+APK_TEST="../src/apk-test"
TEST_TO_RUN="$@"
fail=0