From 60f8d520898bafcd9ce831b04ea4aee9c206fd1d Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Wed, 28 Dec 2022 14:42:23 +0200 Subject: cache, upgrade: do not continue if repositories have issues There are subtle issues where solving fails with --available, and install_if rules if the repository indexes are not available. Also it can be considered upgrade failure if index update failed. Abort cache download, cache sync and upgrade operations early in the above mentioned cases. Also document side effects of --simulate that might affect upgrade. fixes #10726, #10764 --- doc/apk.8.scd | 5 ++++- src/app_cache.c | 10 +++++++++- src/app_upgrade.c | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/doc/apk.8.scd b/doc/apk.8.scd index 86eae96..d924041 100644 --- a/doc/apk.8.scd +++ b/doc/apk.8.scd @@ -189,7 +189,10 @@ The following options are available for all commands. The following options are available for all commands which commit the database. *-s, --simulate* - Simulate the requested operation without making any changes. + Simulate the requested operation without making any changes. The database + is opened in read only mode, and auto-updating of indexes is disabled. + You may want to run "apk update" before running a simulation to make sure + it is done with up-to-date repository indexes. *--clean-protected* Do not create .apk-new files in configuration directories. diff --git a/src/app_cache.c b/src/app_cache.c index 9f526cc..8a91dba 100644 --- a/src/app_cache.c +++ b/src/app_cache.c @@ -201,11 +201,19 @@ static int cache_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *ar return -EINVAL; if (!apk_db_cache_active(db)) { - apk_err(out, "Package cache is not enabled.\n"); + apk_err(out, "Package cache is not enabled."); r = 2; goto err; } + if ((actions & CACHE_DOWNLOAD) && (cctx->solver_flags || cctx->add_dependencies)) { + if (db->repositories.stale || db->repositories.unavailable) { + apk_err(out, "Not continuing due to stale/unavailable repositories."); + r = 3; + goto err; + } + } + if (r == 0 && (actions & CACHE_CLEAN)) r = cache_clean(db); if (r == 0 && (actions & CACHE_DOWNLOAD)) diff --git a/src/app_upgrade.c b/src/app_upgrade.c index 3edd0b1..e0ebcf5 100644 --- a/src/app_upgrade.c +++ b/src/app_upgrade.c @@ -170,6 +170,10 @@ static int upgrade_main(void *ctx, struct apk_ctx *ac, struct apk_string_array * "Use --force-broken-world to override."); return -1; } + if (db->repositories.stale || db->repositories.unavailable) { + apk_err(out, "Not continuing due to stale/unavailable repositories."); + return -1; + } solver_flags = APK_SOLVERF_UPGRADE | uctx->solver_flags; if (!uctx->no_self_upgrade && !args->num) { -- cgit v1.2.3-70-g09d2