diff options
author | Timo Teräs <timo.teras@iki.fi> | 2023-01-31 14:44:26 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2023-01-31 14:44:26 +0200 |
commit | 609fd2187031c2401bbaa303b3cb877ab29eb44c (patch) | |
tree | ab59deb01a7df446b6a92230b046eca54ec88d53 /src | |
parent | d6772adceccceaa1bee2254b6d29890e0aaaae08 (diff) | |
download | apk-tools-609fd2187031c2401bbaa303b3cb877ab29eb44c.tar.gz apk-tools-609fd2187031c2401bbaa303b3cb877ab29eb44c.tar.bz2 apk-tools-609fd2187031c2401bbaa303b3cb877ab29eb44c.tar.xz apk-tools-609fd2187031c2401bbaa303b3cb877ab29eb44c.zip |
cache: fix 'clean' to prune static cache always
Fix cache applet to prune the static cache which is used for index
files if explicit caching is not enabled.
fixes #10754
Diffstat (limited to 'src')
-rw-r--r-- | src/apk_database.h | 4 | ||||
-rw-r--r-- | src/app_cache.c | 30 | ||||
-rw-r--r-- | src/database.c | 16 |
3 files changed, 29 insertions, 21 deletions
diff --git a/src/apk_database.h b/src/apk_database.h index ccc6717..dbdbb3d 100644 --- a/src/apk_database.h +++ b/src/apk_database.h @@ -236,10 +236,10 @@ int apk_cache_download(struct apk_database *db, struct apk_repository *repo, struct apk_package *pkg, int autoupdate, apk_progress_cb cb, void *cb_ctx); -typedef void (*apk_cache_item_cb)(struct apk_database *db, +typedef void (*apk_cache_item_cb)(struct apk_database *db, int static_cache, int dirfd, const char *name, struct apk_package *pkg); -int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb); +int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb, int static_cache); int apk_db_install_pkg(struct apk_database *db, struct apk_package *oldpkg, diff --git a/src/app_cache.c b/src/app_cache.c index 8a91dba..8a3f126 100644 --- a/src/app_cache.c +++ b/src/app_cache.c @@ -143,20 +143,21 @@ static int cache_download(struct cache_ctx *cctx, struct apk_database *db, struc return ret; } -static void cache_clean_item(struct apk_database *db, int dirfd, const char *name, struct apk_package *pkg) +static void cache_clean_item(struct apk_database *db, int static_cache, int dirfd, const char *name, struct apk_package *pkg) { struct apk_out *out = &db->ctx->out; char tmp[PATH_MAX]; apk_blob_t b; int i; - if (strcmp(name, "installed") == 0) return; - - if (pkg) { - if ((db->ctx->flags & APK_PURGE) && pkg->ipkg == NULL) 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; + if (!static_cache) { + if (strcmp(name, "installed") == 0) return; + if (pkg) { + if ((db->ctx->flags & APK_PURGE) && pkg->ipkg == NULL) 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; + } } b = APK_BLOB_STR(name); @@ -176,7 +177,11 @@ delete: static int cache_clean(struct apk_database *db) { - return apk_db_cache_foreach_item(db, cache_clean_item); + if (apk_db_cache_active(db)) { + int r = apk_db_cache_foreach_item(db, cache_clean_item, 0); + if (r) return r; + } + return apk_db_cache_foreach_item(db, cache_clean_item, 1); } static int cache_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *args) @@ -200,11 +205,8 @@ static int cache_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *ar else return -EINVAL; - if (!apk_db_cache_active(db)) { - apk_err(out, "Package cache is not enabled."); - r = 2; - goto err; - } + if (!apk_db_cache_active(db)) + actions &= CACHE_CLEAN; if ((actions & CACHE_DOWNLOAD) && (cctx->solver_flags || cctx->add_dependencies)) { if (db->repositories.stale || db->repositories.unavailable) { diff --git a/src/database.c b/src/database.c index 9cbe20e..1e34cf9 100644 --- a/src/database.c +++ b/src/database.c @@ -1363,7 +1363,7 @@ static void handle_alarm(int sig) { } -static void mark_in_cache(struct apk_database *db, int dirfd, const char *name, struct apk_package *pkg) +static void mark_in_cache(struct apk_database *db, int static_cache, int dirfd, const char *name, struct apk_package *pkg) { if (pkg == NULL) return; @@ -1787,7 +1787,7 @@ int apk_db_open(struct apk_database *db, struct apk_ctx *ac) } if (apk_db_cache_active(db) && (ac->open_flags & (APK_OPENF_NO_REPOS|APK_OPENF_NO_INSTALLED)) == 0) - apk_db_cache_foreach_item(db, mark_in_cache); + apk_db_cache_foreach_item(db, mark_in_cache, 0); db->open_complete = 1; @@ -2131,6 +2131,7 @@ int apk_db_cache_active(struct apk_database *db) struct foreach_cache_item_ctx { struct apk_database *db; apk_cache_item_cb cb; + int static_cache; }; static int foreach_cache_file(void *pctx, int dirfd, const char *name) @@ -2160,15 +2161,20 @@ static int foreach_cache_file(void *pctx, int dirfd, const char *name) } } no_pkg: - ctx->cb(db, dirfd, name, pkg); + ctx->cb(db, ctx->static_cache, dirfd, name, pkg); return 0; } -int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb) +int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb, int static_cache) { - struct foreach_cache_item_ctx ctx = { db, cb }; + struct foreach_cache_item_ctx ctx = { db, cb, static_cache }; + if (static_cache) { + return apk_dir_foreach_file( + openat(db->root_fd, apk_static_cache_dir, O_RDONLY | O_CLOEXEC), + foreach_cache_file, &ctx); + } if (db->cache_fd < 0) return db->cache_fd; return apk_dir_foreach_file(dup(db->cache_fd), foreach_cache_file, &ctx); } |