Commit e2afc7e7 authored by Timo Teräs's avatar Timo Teräs

fix, simplify and document upgrade --ignore

parent f3cf8249
Pipeline #42647 passed with stage
in 42 seconds
......@@ -11,7 +11,9 @@ apk upgrade - upgrade installed packages
# DESCRIPTION
*apk upgrade* upgrades installed packages to the latest version available from
configured package repositories (see *apk-repositories*(5)).
configured package repositories (see *apk-repositories*(5)). When no packages
are specified, all packages are upgraded if possible. If list of packages is
provided, only those packages are upgraded along with needed dependencies.
# OPTIONS
......@@ -27,6 +29,10 @@ following options:
This is useful to reset system against new set of packages after updating
repositories.
*--ignore*
Upgrade all other packages than the ones listed. This inverts the given
package name list to mean packages that should not be upgraded.
*-l, --latest*
Always choose the latest package by version. However, the versions
considered are based on the package pinning. Primarily this overrides
......
......@@ -96,15 +96,11 @@ struct apk_installed_package {
struct apk_package {
apk_hash_node hash_node;
unsigned int foreach_genid;
union {
struct apk_solver_package_state ss;
struct {
unsigned int foreach_genid;
union {
int state_int;
void *state_ptr;
};
};
int state_int;
void *state_ptr;
};
struct apk_name *name;
struct apk_installed_package *ipkg;
......
......@@ -33,7 +33,7 @@ struct apk_changeset {
#define APK_SOLVERF_REINSTALL 0x0004
#define APK_SOLVERF_LATEST 0x0008
#define APK_SOLVERF_IGNORE_CONFLICT 0x0010
#define APK_SOLVERF_IGNORE_UPGRADE 0x0020
#define APK_SOLVERF_INSTALLED 0x0020
void apk_solver_set_name_flags(struct apk_name *name,
unsigned short solver_flags,
......
......@@ -138,8 +138,10 @@ static void set_upgrade_for_name(struct apk_database *db, const char *match, str
if (!name) {
apk_error("Package '%s' not found", match);
uctx->errors++;
} else
apk_solver_set_name_flags(name, APK_SOLVERF_UPGRADE, 0);
return;
}
apk_solver_set_name_flags(name, uctx->ignore ? APK_SOLVERF_INSTALLED : APK_SOLVERF_UPGRADE, 0);
}
static int upgrade_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
......@@ -157,7 +159,7 @@ 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) {
if (!uctx->no_self_upgrade && !args->num) {
r = apk_do_self_upgrade(db, solver_flags, uctx->self_upgrade_only);
if (r != 0)
return r;
......@@ -165,15 +167,6 @@ static int upgrade_main(void *ctx, struct apk_database *db, struct apk_string_ar
if (uctx->self_upgrade_only)
return 0;
if (uctx->ignore) {
char **pkg_name;
struct apk_name *name;
foreach_array_item(pkg_name, args) {
name = apk_db_get_name(db, APK_BLOB_STR(*pkg_name));
apk_solver_set_name_flags(name, solver_flags | APK_SOLVERF_IGNORE_UPGRADE, 0);
}
}
if (solver_flags & APK_SOLVERF_AVAILABLE) {
apk_dependency_array_copy(&world, db->world);
foreach_array_item(dep, world) {
......@@ -188,12 +181,9 @@ static int upgrade_main(void *ctx, struct apk_database *db, struct apk_string_ar
if (args->num > 0) {
/* if specific packages are listed, we don't want to upgrade world. */
solver_flags &= ~APK_SOLVERF_UPGRADE;
apk_name_foreach_matching(db, args, apk_foreach_genid(), set_upgrade_for_name, &uctx);
if (uctx->errors)
return uctx->errors;
if (!uctx->ignore) solver_flags &= ~APK_SOLVERF_UPGRADE;
apk_name_foreach_matching(db, args, apk_foreach_genid(), set_upgrade_for_name, uctx);
if (uctx->errors) return uctx->errors;
}
r = apk_solver_commit(db, solver_flags, world);
......
......@@ -53,6 +53,8 @@ void apk_solver_set_name_flags(struct apk_name *name,
foreach_array_item(p, name->providers) {
struct apk_package *pkg = p->pkg;
dbg_printf("marking '" PKG_VER_FMT "' = 0x%04x / 0x%04x\n",
PKG_VER_PRINTF(pkg), solver_flags, solver_flags_inheritable);
pkg->ss.solver_flags |= solver_flags;
pkg->ss.solver_flags_inheritable |= solver_flags_inheritable;
}
......@@ -564,10 +566,10 @@ static int compare_providers(struct apk_solver_state *ss,
/* Prefer installed on self-upgrade */
if ((db->performing_self_upgrade && !(solver_flags & APK_SOLVERF_UPGRADE)) ||
(solver_flags & APK_SOLVERF_IGNORE_UPGRADE)) {
(solver_flags & APK_SOLVERF_INSTALLED)) {
r = (pkgA->ipkg != NULL) - (pkgB->ipkg != NULL);
if (r) {
dbg_printf(" prefer installed on self-upgrade\n");
dbg_printf(" prefer installed\n");
return r;
}
}
......@@ -603,8 +605,7 @@ static int compare_providers(struct apk_solver_state *ss,
}
/* Prefer installed */
if (!(solver_flags & APK_SOLVERF_UPGRADE) ||
(solver_flags & APK_SOLVERF_IGNORE_UPGRADE)) {
if (!(solver_flags & APK_SOLVERF_UPGRADE)) {
r = (pkgA->ipkg != NULL) - (pkgB->ipkg != NULL);
if (r) {
dbg_printf(" prefer installed\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment