summaryrefslogtreecommitdiff
path: root/src/app_cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/app_cache.c')
-rw-r--r--src/app_cache.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/app_cache.c b/src/app_cache.c
index 09d9adf..7239faa 100644
--- a/src/app_cache.c
+++ b/src/app_cache.c
@@ -142,19 +142,20 @@ 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)
{
char tmp[PATH_MAX];
apk_blob_t b;
int i;
- if (strcmp(name, "installed") == 0) return;
-
- if (pkg) {
- if ((apk_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 ((apk_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);
@@ -175,7 +176,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_database *db, struct apk_string_array *args)
@@ -197,11 +202,8 @@ static int cache_main(void *ctx, struct apk_database *db, struct apk_string_arra
else
return -EINVAL;
- if (!apk_db_cache_active(db)) {
- apk_error("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) {