From e2afc7e7a9960eaf6cb40267bc1f39aa6638dccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Mon, 24 Aug 2020 15:26:25 +0300 Subject: [PATCH] fix, simplify and document upgrade --ignore --- doc/apk-upgrade.8.scd | 8 +++++++- src/apk_package.h | 10 +++------- src/apk_solver.h | 2 +- src/app_upgrade.c | 26 ++++++++------------------ src/solver.c | 9 +++++---- 5 files changed, 24 insertions(+), 31 deletions(-) diff --git a/doc/apk-upgrade.8.scd b/doc/apk-upgrade.8.scd index 74622d9..a7c77f4 100644 --- a/doc/apk-upgrade.8.scd +++ b/doc/apk-upgrade.8.scd @@ -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 diff --git a/src/apk_package.h b/src/apk_package.h index 08de452..6e428e4 100644 --- a/src/apk_package.h +++ b/src/apk_package.h @@ -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; diff --git a/src/apk_solver.h b/src/apk_solver.h index 35ef4f8..c386b13 100644 --- a/src/apk_solver.h +++ b/src/apk_solver.h @@ -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, diff --git a/src/app_upgrade.c b/src/app_upgrade.c index b666d8e..b9c50d5 100644 --- a/src/app_upgrade.c +++ b/src/app_upgrade.c @@ -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); diff --git a/src/solver.c b/src/solver.c index 7d3654b..df63060 100644 --- a/src/solver.c +++ b/src/solver.c @@ -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");