cache: delete more aggressively unneeded cached files

Also if --purge is specified delete all uninstalled packages.
Fixes #2889
cute-signatures
Timo Teräs 2014-10-06 15:52:51 +03:00
parent f5674b9582
commit f2d9a14405
2 changed files with 12 additions and 6 deletions

View File

@ -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 "

View File

@ -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,
};