cache: delete also wget temporary files

check for the full filename to match an expected pattern or
delete it (so we delete files with .new, .new.backup, etc.).
final part of remote package caching: fixes #49.
cute-signatures
Timo Teras 2009-07-07 09:40:59 +03:00
parent b551c3b081
commit dc5c436c5a
1 changed files with 10 additions and 2 deletions

View File

@ -67,6 +67,7 @@ static int cache_clean(struct apk_database *db)
{ {
DIR *dir; DIR *dir;
struct dirent *de; struct dirent *de;
struct apk_package *pkg;
char path[256]; char path[256];
int delete, i; int delete, i;
csum_t csum; csum_t csum;
@ -102,13 +103,20 @@ static int cache_clean(struct apk_database *db)
delete = (i >= db->num_repos); delete = (i >= db->num_repos);
} else { } else {
/* Package - search for it */ /* Package - search for it */
delete = (apk_db_get_pkg(db, csum) == NULL); pkg = apk_db_get_pkg(db, csum);
if (pkg == NULL)
break;
snprintf(path, sizeof(path), "%s-%s.apk",
pkg->name->name, pkg->version);
delete = strcmp(&de->d_name[sizeof(csum_t)*2+1],
path);
} }
} while (0); } while (0);
if (delete) { if (delete) {
if (apk_verbosity >= 2) if (apk_verbosity >= 2)
apk_message("Deleting %s", de->d_name); apk_message("deleting %s", de->d_name);
if (!(apk_flags & APK_SIMULATE)) if (!(apk_flags & APK_SIMULATE))
unlink(de->d_name); unlink(de->d_name);
} }