Commit ba76c5f4 authored by Timo Teräs's avatar Timo Teräs

cache: make cache cleaning work again properly

parent a7c5fda4
...@@ -84,6 +84,8 @@ struct apk_package *apk_pkg_new(void); ...@@ -84,6 +84,8 @@ struct apk_package *apk_pkg_new(void);
struct apk_package *apk_pkg_read(struct apk_database *db, const char *name); struct apk_package *apk_pkg_read(struct apk_database *db, const char *name);
void apk_pkg_free(struct apk_package *pkg); void apk_pkg_free(struct apk_package *pkg);
int apk_pkg_parse_name(apk_blob_t apkname, apk_blob_t *name, apk_blob_t *version);
int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg, int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg,
char field, apk_blob_t value); char field, apk_blob_t value);
int apk_pkg_get_state(struct apk_package *pkg); int apk_pkg_get_state(struct apk_package *pkg);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "apk_applet.h" #include "apk_applet.h"
#include "apk_database.h" #include "apk_database.h"
#include "apk_state.h" #include "apk_state.h"
#include "apk_package.h"
#define CACHE_CLEAN BIT(0) #define CACHE_CLEAN BIT(0)
#define CACHE_DOWNLOAD BIT(1) #define CACHE_DOWNLOAD BIT(1)
...@@ -70,7 +71,8 @@ static int cache_clean(struct apk_database *db) ...@@ -70,7 +71,8 @@ static int cache_clean(struct apk_database *db)
struct dirent *de; struct dirent *de;
char path[256], csum[APK_CACHE_CSUM_BYTES]; char path[256], csum[APK_CACHE_CSUM_BYTES];
int delete, i; 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); snprintf(path, sizeof(path), "%s/%s", db->root, db->cache_dir);
if (chdir(path) != 0) if (chdir(path) != 0)
...@@ -85,35 +87,36 @@ static int cache_clean(struct apk_database *db) ...@@ -85,35 +87,36 @@ static int cache_clean(struct apk_database *db)
continue; continue;
delete = TRUE; delete = TRUE;
do { do {
if (strlen(de->d_name) <= APK_CACHE_CSUM_BYTES*2+2) b = APK_BLOB_STR(de->d_name);
break;
b = APK_BLOB_PTR_LEN(de->d_name, APK_CACHE_CSUM_BYTES*2);
apk_blob_pull_hexdump(&b, APK_BLOB_BUF(csum)); apk_blob_pull_hexdump(&b, APK_BLOB_BUF(csum));
if (APK_BLOB_IS_NULL(b)) apk_blob_pull_char(&b, '.');
break;
if (de->d_name[APK_CACHE_CSUM_BYTES*2] != '.') if (apk_blob_compare(b, APK_BLOB_STR(apk_index_gz)) == 0) {
break;
if (strcmp(&de->d_name[APK_CACHE_CSUM_BYTES*2+1],
apk_index_gz) == 0) {
/* Index - check for matching repository */ /* 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, if (memcmp(db->repos[i].csum.data,
csum, APK_CACHE_CSUM_BYTES) == 0) csum, APK_CACHE_CSUM_BYTES) != 0)
continue;
delete = 0;
break; break;
delete = (i >= db->num_repos); }
} else { } else if (b.len > 4 &&
memcmp(b.ptr+b.len-4, ".apk", 4) == 0) {
/* Package - search for it */ /* Package - search for it */
#if 0 if (apk_pkg_parse_name(b, &bname, &bver) < 0)
pkg = apk_db_get_pkg(db, csum);
if (pkg == NULL)
break; break;
snprintf(path, sizeof(path), "%s-%s.apk", name = apk_db_get_name(db, bname);
pkg->name->name, pkg->version); if (name == NULL || name->pkgs == NULL)
delete = strcmp(&de->d_name[sizeof(csum_t)*2+1], break;
path);
#endif for (i = 0; i < name->pkgs->num; i++) {
//#warning FIXME - need to check if cache file is valid - look up using name, check csum 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); } while (0);
......
...@@ -43,6 +43,9 @@ int apk_pkg_parse_name(apk_blob_t apkname, ...@@ -43,6 +43,9 @@ int apk_pkg_parse_name(apk_blob_t apkname,
{ {
int i, dash = 0; int i, dash = 0;
if (APK_BLOB_IS_NULL(apkname))
return -1;
for (i = apkname.len - 2; i >= 0; i--) { for (i = apkname.len - 2; i >= 0; i--) {
if (apkname.ptr[i] != '-') if (apkname.ptr[i] != '-')
continue; continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment