summaryrefslogtreecommitdiff
path: root/src/cache.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2014-10-06 15:52:51 +0300
committerTimo Teräs <timo.teras@iki.fi>2014-10-06 15:54:52 +0300
commitf2d9a1440546da4fc9302a93370039b3a12c77ce (patch)
treedc1b68675ccda6090607390aebc9b776920e8ee9 /src/cache.c
parentf5674b95824126a5f8545103edd76e000a2a3c56 (diff)
downloadapk-tools-f2d9a1440546da4fc9302a93370039b3a12c77ce.tar.gz
apk-tools-f2d9a1440546da4fc9302a93370039b3a12c77ce.tar.bz2
apk-tools-f2d9a1440546da4fc9302a93370039b3a12c77ce.tar.xz
apk-tools-f2d9a1440546da4fc9302a93370039b3a12c77ce.zip
cache: delete more aggressively unneeded cached files
Also if --purge is specified delete all uninstalled packages. Fixes #2889
Diffstat (limited to 'src/cache.c')
-rw-r--r--src/cache.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/cache.c b/src/cache.c
index 25c9a23..f694085 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -84,17 +84,23 @@ static void cache_clean_item(struct apk_database *db, int dirfd, const char *nam
apk_blob_t b;
int i;
- if (pkg != NULL || strcmp(name, "installed") == 0)
+ 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);
for (i = 0; i < db->num_repos; i++) {
/* Check if this is a valid index */
apk_repo_format_cache_index(APK_BLOB_BUF(tmp), &db->repos[i]);
- if (apk_blob_compare(b, APK_BLOB_STR(tmp)) == 0)
- return;
+ if (apk_blob_compare(b, APK_BLOB_STR(tmp)) == 0) return;
}
+delete:
if (apk_verbosity >= 2)
apk_message("deleting %s", name);
if (!(apk_flags & APK_SIMULATE)) {
@@ -145,7 +151,7 @@ static struct apk_applet apk_cache = {
.help = "Download missing PACKAGEs to cache and/or delete "
"unneeded files from cache",
.arguments = "sync | clean | download",
- .open_flags = APK_OPENF_READ|APK_OPENF_NO_SCRIPTS|APK_OPENF_NO_INSTALLED|APK_OPENF_CACHE_WRITE,
+ .open_flags = APK_OPENF_READ|APK_OPENF_NO_SCRIPTS|APK_OPENF_CACHE_WRITE,
.main = cache_main,
};