upgrade: improve self upgrade functionality a bit
trigger it only if apk-tools can be upgrade, add test casescute-signatures
parent
22434a5ff0
commit
ac0a9659d1
|
@ -150,7 +150,7 @@ struct apk_database {
|
||||||
unsigned int local_repos, available_repos;
|
unsigned int local_repos, available_repos;
|
||||||
int repo_update_errors;
|
int repo_update_errors;
|
||||||
unsigned int pending_triggers;
|
unsigned int pending_triggers;
|
||||||
int performing_self_update : 1;
|
int performing_self_upgrade : 1;
|
||||||
int permanent : 1;
|
int permanent : 1;
|
||||||
int open_complete : 1;
|
int open_complete : 1;
|
||||||
int compat_newfeatures : 1;
|
int compat_newfeatures : 1;
|
||||||
|
|
|
@ -309,7 +309,7 @@ all_done:
|
||||||
apk_dependency_array_copy(&db->world, world);
|
apk_dependency_array_copy(&db->world, world);
|
||||||
apk_db_write_config(db);
|
apk_db_write_config(db);
|
||||||
|
|
||||||
if (!db->performing_self_update) {
|
if (!db->performing_self_upgrade) {
|
||||||
if (errors)
|
if (errors)
|
||||||
snprintf(buf, sizeof(buf), "%d errors;", errors);
|
snprintf(buf, sizeof(buf), "%d errors;", errors);
|
||||||
else
|
else
|
||||||
|
|
|
@ -482,6 +482,7 @@ static int compare_providers(struct apk_solver_state *ss,
|
||||||
unsigned int solver_flags;
|
unsigned int solver_flags;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
|
||||||
/* Prefer existing package */
|
/* Prefer existing package */
|
||||||
if (pkgA == NULL || pkgB == NULL)
|
if (pkgA == NULL || pkgB == NULL)
|
||||||
return (pkgA != NULL) - (pkgB != NULL);
|
return (pkgA != NULL) - (pkgB != NULL);
|
||||||
|
@ -521,7 +522,7 @@ static int compare_providers(struct apk_solver_state *ss,
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
/* Prefer installed on self-upgrade */
|
/* 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);
|
r = (pkgA->ipkg != NULL) - (pkgB->ipkg != NULL);
|
||||||
if (r)
|
if (r)
|
||||||
return 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) {
|
if (name->ss.requirers || name->ss.has_iif) {
|
||||||
foreach_array_item(p, name->providers) {
|
foreach_array_item(p, name->providers) {
|
||||||
dbg_printf(" consider "PKG_VER_FMT" iif_triggered=%d, tag_ok=%d\n",
|
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);
|
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 */
|
/* Ensure valid pinning and install-if trigger */
|
||||||
if (name->ss.requirers == 0 &&
|
if (name->ss.requirers == 0 &&
|
||||||
(!p->pkg->ss.iif_triggered ||
|
(!p->pkg->ss.iif_triggered ||
|
||||||
|
@ -979,7 +980,7 @@ restart:
|
||||||
pkg = name->ss.chosen.pkg;
|
pkg = name->ss.chosen.pkg;
|
||||||
if (pkg == NULL || pkg->ss.error) {
|
if (pkg == NULL || pkg->ss.error) {
|
||||||
d->broken = 1;
|
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);
|
apk_hash_foreach(&db->available.names, free_name, NULL);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
struct upgrade_ctx {
|
struct upgrade_ctx {
|
||||||
unsigned short solver_flags;
|
unsigned short solver_flags;
|
||||||
int no_self_upgrade : 1;
|
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)
|
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:
|
case 0x10000:
|
||||||
uctx->no_self_upgrade = 1;
|
uctx->no_self_upgrade = 1;
|
||||||
break;
|
break;
|
||||||
|
case 0x10001:
|
||||||
|
uctx->self_upgrade_only = 1;
|
||||||
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
uctx->solver_flags |= APK_SOLVERF_AVAILABLE;
|
uctx->solver_flags |= APK_SOLVERF_AVAILABLE;
|
||||||
break;
|
break;
|
||||||
|
@ -54,6 +58,7 @@ static const struct apk_option options_applet[] = {
|
||||||
"print error if it cannot be installed due to other dependencies" },
|
"print error if it cannot be installed due to other dependencies" },
|
||||||
{ 0x10000, "no-self-upgrade",
|
{ 0x10000, "no-self-upgrade",
|
||||||
"Do not do early upgrade of 'apk-tools' package" },
|
"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 = {
|
static const struct apk_option_group optgroup_applet = {
|
||||||
|
@ -63,32 +68,56 @@ static const struct apk_option_group optgroup_applet = {
|
||||||
.parse = option_parse_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_name *name;
|
||||||
|
struct apk_package *pkg;
|
||||||
|
struct apk_provider *p0;
|
||||||
struct apk_changeset changeset = {};
|
struct apk_changeset changeset = {};
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
name = apk_db_get_name(db, APK_BLOB_STR("apk-tools"));
|
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);
|
apk_solver_set_name_flags(name, solver_flags, 0);
|
||||||
db->performing_self_update = 1;
|
|
||||||
|
|
||||||
r = apk_solver_solve(db, 0, db->world, &changeset);
|
r = apk_solver_solve(db, 0, db->world, &changeset);
|
||||||
if (r != 0) {
|
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;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changeset.num_total_changes == 0)
|
if (changeset.num_total_changes == 0)
|
||||||
goto ret;
|
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.");
|
apk_warning("This simulation is not reliable as apk-tools upgrade is available.");
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
apk_message("Upgrading critical system libraries and apk-tools:");
|
apk_message("Upgrading critical system libraries and apk-tools:");
|
||||||
apk_solver_commit_changeset(db, &changeset, db->world);
|
apk_solver_commit_changeset(db, &changeset, db->world);
|
||||||
|
if (self_upgrade_only) goto ret;
|
||||||
|
|
||||||
apk_db_close(db);
|
apk_db_close(db);
|
||||||
|
|
||||||
apk_message("Continuing the upgrade transaction with new apk-tools:");
|
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:
|
ret:
|
||||||
apk_change_array_free(&changeset.changes);
|
apk_change_array_free(&changeset.changes);
|
||||||
db->performing_self_update = 0;
|
db->performing_self_upgrade = 0;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +141,7 @@ static int upgrade_main(void *ctx, struct apk_database *db, struct apk_string_ar
|
||||||
unsigned short solver_flags;
|
unsigned short solver_flags;
|
||||||
struct apk_dependency *dep;
|
struct apk_dependency *dep;
|
||||||
struct apk_dependency_array *world = NULL;
|
struct apk_dependency_array *world = NULL;
|
||||||
int r;
|
int r = 0;
|
||||||
|
|
||||||
if (apk_db_check_world(db, db->world) != 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.");
|
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;
|
solver_flags = APK_SOLVERF_UPGRADE | uctx->solver_flags;
|
||||||
if (!uctx->no_self_upgrade) {
|
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)
|
if (r != 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
if (uctx->self_upgrade_only)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (solver_flags & APK_SOLVERF_AVAILABLE) {
|
if (solver_flags & APK_SOLVERF_AVAILABLE) {
|
||||||
apk_dependency_array_copy(&world, db->world);
|
apk_dependency_array_copy(&world, db->world);
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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)
|
|
@ -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
|
|
@ -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)
|
|
@ -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
|
|
@ -0,0 +1,7 @@
|
||||||
|
@ARGS
|
||||||
|
--test-repo selfupgrade.repo
|
||||||
|
--test-instdb selfupgrade2.installed
|
||||||
|
--test-world "apk-tools application"
|
||||||
|
--self-upgrade-only
|
||||||
|
upgrade
|
||||||
|
@EXPECT
|
|
@ -0,0 +1,7 @@
|
||||||
|
@ARGS
|
||||||
|
--test-repo selfupgrade.repo
|
||||||
|
--test-instdb selfupgrade3.installed
|
||||||
|
--test-world "apk-tools"
|
||||||
|
--self-upgrade-only
|
||||||
|
upgrade
|
||||||
|
@EXPECT
|
|
@ -4,7 +4,7 @@ get_block() {
|
||||||
awk '/^@'$1'/{p=1;next} /^@/{p=0} p{print}'
|
awk '/^@'$1'/{p=1;next} /^@/{p=0} p{print}'
|
||||||
}
|
}
|
||||||
|
|
||||||
APK_TEST=../src/apk-test
|
APK_TEST="../src/apk-test"
|
||||||
TEST_TO_RUN="$@"
|
TEST_TO_RUN="$@"
|
||||||
|
|
||||||
fail=0
|
fail=0
|
||||||
|
|
Loading…
Reference in New Issue