From cf3dfb7611f9055034b55f4caf7d145ce3e04af4 Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Fri, 16 Jan 2009 09:32:04 +0200 Subject: db, hash: fix package purging/upgrading to update filedb properly --- src/hash.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/hash.c') 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; + } + } + } } -- cgit v1.2.3-60-g2f50