aboutsummaryrefslogtreecommitdiffstats
path: root/src/cache.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-07-15 15:59:06 +0300
committerTimo Teras <timo.teras@iki.fi>2009-07-15 15:59:06 +0300
commitba76c5f48ae584c4085ef97fb16e5a6f72adfe25 (patch)
tree591de04ad42b0bdcdf51e1926f368e68a1a55172 /src/cache.c
parenta7c5fda40ac76c4a43af7a4ee5241514f890a2ee (diff)
downloadapk-tools-ba76c5f48ae584c4085ef97fb16e5a6f72adfe25.tar.gz
apk-tools-ba76c5f48ae584c4085ef97fb16e5a6f72adfe25.tar.bz2
apk-tools-ba76c5f48ae584c4085ef97fb16e5a6f72adfe25.tar.xz
cache: make cache cleaning work again properly
Diffstat (limited to 'src/cache.c')
-rw-r--r--src/cache.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/cache.c b/src/cache.c
index a5643c4..7bcd636 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -17,6 +17,7 @@
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_state.h"
+#include "apk_package.h"
#define CACHE_CLEAN BIT(0)
#define CACHE_DOWNLOAD BIT(1)
@@ -70,7 +71,8 @@ static int cache_clean(struct apk_database *db)
struct dirent *de;
char path[256], csum[APK_CACHE_CSUM_BYTES];
int delete, i;
- apk_blob_t b;
+ apk_blob_t b, bname, bver;
+ struct apk_name *name;
snprintf(path, sizeof(path), "%s/%s", db->root, db->cache_dir);
if (chdir(path) != 0)
@@ -85,35 +87,36 @@ static int cache_clean(struct apk_database *db)
continue;
delete = TRUE;
do {
- if (strlen(de->d_name) <= APK_CACHE_CSUM_BYTES*2+2)
- break;
- b = APK_BLOB_PTR_LEN(de->d_name, APK_CACHE_CSUM_BYTES*2);
+ b = APK_BLOB_STR(de->d_name);
apk_blob_pull_hexdump(&b, APK_BLOB_BUF(csum));
- if (APK_BLOB_IS_NULL(b))
- break;
- if (de->d_name[APK_CACHE_CSUM_BYTES*2] != '.')
- break;
- if (strcmp(&de->d_name[APK_CACHE_CSUM_BYTES*2+1],
- apk_index_gz) == 0) {
+ apk_blob_pull_char(&b, '.');
+
+ if (apk_blob_compare(b, APK_BLOB_STR(apk_index_gz)) == 0) {
/* Index - check for matching repository */
- for (i = 0; i < db->num_repos; i++)
+ for (i = 0; i < db->num_repos; i++) {
if (memcmp(db->repos[i].csum.data,
- csum, APK_CACHE_CSUM_BYTES) == 0)
- break;
- delete = (i >= db->num_repos);
- } else {
+ csum, APK_CACHE_CSUM_BYTES) != 0)
+ continue;
+ delete = 0;
+ break;
+ }
+ } else if (b.len > 4 &&
+ memcmp(b.ptr+b.len-4, ".apk", 4) == 0) {
/* Package - search for it */
-#if 0
- pkg = apk_db_get_pkg(db, csum);
- if (pkg == NULL)
+ if (apk_pkg_parse_name(b, &bname, &bver) < 0)
break;
- snprintf(path, sizeof(path), "%s-%s.apk",
- pkg->name->name, pkg->version);
- delete = strcmp(&de->d_name[sizeof(csum_t)*2+1],
- path);
-#endif
-//#warning FIXME - need to check if cache file is valid - look up using name, check csum
+ name = apk_db_get_name(db, bname);
+ if (name == NULL || name->pkgs == NULL)
+ break;
+
+ for (i = 0; i < name->pkgs->num; i++) {
+ struct apk_package *pkg = name->pkgs->item[i];
+ if (memcmp(pkg->csum.data, csum, APK_CACHE_CSUM_BYTES) != 0)
+ continue;
+ delete = 0;
+ break;
+ }
}
} while (0);