diff options
author | Timo Teräs <timo.teras@iki.fi> | 2014-10-06 15:52:51 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2014-10-06 15:54:52 +0300 |
commit | f2d9a1440546da4fc9302a93370039b3a12c77ce (patch) | |
tree | dc1b68675ccda6090607390aebc9b776920e8ee9 | |
parent | f5674b95824126a5f8545103edd76e000a2a3c56 (diff) | |
download | apk-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
-rw-r--r-- | src/apk.c | 4 | ||||
-rw-r--r-- | src/cache.c | 14 |
2 files changed, 12 insertions, 6 deletions
@@ -55,8 +55,8 @@ static struct apk_option generic_options[] = { { 0x110, "no-progress", "Disable progress bar even for TTYs" }, { 0x102, "clean-protected", "Do not create .apk-new files in " "configuration dirs" }, - { 0x106, "purge", "Delete also modified configuration files on " - "package removal" }, + { 0x106, "purge", "Delete also modified configuration files (pkg removal) " + "and uninstalled packages from cache (cache clean)" }, { 0x103, "allow-untrusted", "Blindly install packages with untrusted " "signatures or no signature at all" }, { 0x104, "simulate", "Show what would be done without actually " 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, }; |