summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apk_package.h2
-rw-r--r--src/cache.c51
-rw-r--r--src/package.c3
3 files changed, 32 insertions, 24 deletions
diff --git a/src/apk_package.h b/src/apk_package.h
index bec495b..a281712 100644
--- a/src/apk_package.h
+++ b/src/apk_package.h
@@ -84,6 +84,8 @@ struct apk_package *apk_pkg_new(void);
struct apk_package *apk_pkg_read(struct apk_database *db, const char *name);
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,
char field, apk_blob_t value);
int apk_pkg_get_state(struct apk_package *pkg);
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);
diff --git a/src/package.c b/src/package.c
index 6c050cf..d408f73 100644
--- a/src/package.c
+++ b/src/package.c
@@ -43,6 +43,9 @@ int apk_pkg_parse_name(apk_blob_t apkname,
{
int i, dash = 0;
+ if (APK_BLOB_IS_NULL(apkname))
+ return -1;
+
for (i = apkname.len - 2; i >= 0; i--) {
if (apkname.ptr[i] != '-')
continue;