summaryrefslogtreecommitdiffstats
path: root/src/hash.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-01-16 09:32:04 +0200
committerTimo Teras <timo.teras@iki.fi>2009-01-16 09:33:05 +0200
commitcf3dfb7611f9055034b55f4caf7d145ce3e04af4 (patch)
tree1dc03ba7f0c82a987f1574d1b59d4c272fde90f3 /src/hash.c
parentfed45e4b7ffe02dd706f51301812bbd9f509229e (diff)
db, hash: fix package purging/upgrading to update filedb properly
Diffstat (limited to 'src/hash.c')
-rw-r--r--src/hash.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/hash.c b/src/hash.c
index a81bb76..ee24a29 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -87,5 +87,33 @@ void apk_hash_insert(struct apk_hash *h, apk_hash_item item)
void apk_hash_delete(struct apk_hash *h, apk_blob_t key)
{
+ ptrdiff_t offset = h->ops->node_offset;
+ unsigned long hash;
+ apk_hash_node *pos;
+ apk_hash_item item;
+ apk_blob_t itemkey;
+
+ hash = h->ops->hash_key(key) % h->buckets->num;
+ if (h->ops->compare_item != NULL) {
+ hlist_for_each(pos, &h->buckets->item[hash]) {
+ item = ((void *) pos) - offset;
+ if (h->ops->compare_item(item, key) == 0) {
+ hlist_del(pos, &h->buckets->item[hash]);
+ h->ops->delete_item(item);
+ return;
+ }
+
+ }
+ } else {
+ hlist_for_each(pos, &h->buckets->item[hash]) {
+ item = ((void *) pos) - offset;
+ itemkey = h->ops->get_key(item);
+ if (h->ops->compare(key, itemkey) == 0) {
+ hlist_del(pos, &h->buckets->item[hash]);
+ h->ops->delete_item(item);
+ return;
+ }
+ }
+ }
}