From cf468e297b73b034eb20f867bee5206c93436754 Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Tue, 31 Jan 2023 15:14:54 +0200 Subject: cache: improve and document purging Document cache clean --purge better. Add a cache purge alias for it. And also purge installed package copies on disk installs. fixes #10857 --- doc/apk-cache.8.scd | 8 +++++++- doc/apk.8.scd | 6 ++++-- src/app_cache.c | 15 ++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/doc/apk-cache.8.scd b/doc/apk-cache.8.scd index e5a9b6f..0a04123 100644 --- a/doc/apk-cache.8.scd +++ b/doc/apk-cache.8.scd @@ -10,6 +10,8 @@ apk cache - manage a local cache of package files *apk cache* [<_options_>...] download [_dependency_...] +*apk cache* [<_options_>...] purge + *apk cache* [<_options_>...] sync [_dependency_...] # DESCRIPTION @@ -23,7 +25,11 @@ default _world_ dependencies are used to determine what to download. If _dependency_ arguments are given, they will by default replace the _world_. *apk cache clean* will remove package files which no longer exist in any -repository index. +repository index. Specifying the global option *--purge* will additionally +remove all uninstalled package on tmpfs installations, and all packages on +disk installations. + +*apk cache purge* is a synonym for *clean --purge*. *apk cache sync* performs both operations. diff --git a/doc/apk.8.scd b/doc/apk.8.scd index d924041..edaa031 100644 --- a/doc/apk.8.scd +++ b/doc/apk.8.scd @@ -171,8 +171,10 @@ The following options are available for all commands. Write progress to the specified file descriptor. *--purge* - Delete modified configuration files on package removal and uninstalled - packages from cache on cache clean. + Purge modified configuration and cached packages. Enables deletion of + modified configuration files on package removal. On cache clean action + this enables deletion of unneeded cached packages (uninstalled packages + on tmpfs installations or all packages on disk installations). *--repositories-file* _REPOFILE_ Override system repositories, see *apk-repositories*(8). Specifying this diff --git a/src/app_cache.c b/src/app_cache.c index 8a3f126..ab192cd 100644 --- a/src/app_cache.c +++ b/src/app_cache.c @@ -153,7 +153,9 @@ static void cache_clean_item(struct apk_database *db, int static_cache, int dirf if (!static_cache) { if (strcmp(name, "installed") == 0) return; if (pkg) { - if ((db->ctx->flags & APK_PURGE) && pkg->ipkg == NULL) goto delete; + if (db->ctx->flags & APK_PURGE) { + if (db->permanent || !pkg->ipkg) goto delete; + } if (pkg->repos & db->local_repos & ~BIT(APK_REPOSITORY_CACHED)) goto delete; if (pkg->ipkg == NULL && !(pkg->repos & ~BIT(APK_REPOSITORY_CACHED))) goto delete; return; @@ -196,13 +198,16 @@ static int cache_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *ar return -EINVAL; arg = args->item[0]; - if (strcmp(arg, "sync") == 0) + if (strcmp(arg, "sync") == 0) { actions = CACHE_CLEAN | CACHE_DOWNLOAD; - else if (strcmp(arg, "clean") == 0) + } else if (strcmp(arg, "clean") == 0) { actions = CACHE_CLEAN; - else if (strcmp(arg, "download") == 0) + } else if (strcmp(arg, "purge") == 0) { + actions = CACHE_CLEAN; + db->ctx->flags |= APK_PURGE; + } else if (strcmp(arg, "download") == 0) { actions = CACHE_DOWNLOAD; - else + } else return -EINVAL; if (!apk_db_cache_active(db)) -- cgit v1.2.3-60-g2f50