From ce577d8db0580112cd8dcd60a1c6110f624a3d2a Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 5 Apr 2013 16:50:20 +0200 Subject: [PATCH] packagefs: AttributeIndex: Support duplicates correctly The tree comparisons didn't allow for different Nodes having the same attribute value. Therefore only the first node would be added and later we would try to remove a node not actually in the tree, leading to a crash. packagefs seems to finally unmount cleanly, now. --- .../file_systems/packagefs/AttributeIndex.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/file_systems/packagefs/AttributeIndex.cpp b/src/add-ons/kernel/file_systems/packagefs/AttributeIndex.cpp index e93a43424a..1f6f62a819 100644 --- a/src/add-ons/kernel/file_systems/packagefs/AttributeIndex.cpp +++ b/src/add-ons/kernel/file_systems/packagefs/AttributeIndex.cpp @@ -89,14 +89,29 @@ struct AttributeIndex::TreeDefinition { int Compare(const Key& a, const Value* b) const { - return QueryParser::compareKeys(fType, a.data, a.length, b->data, + int cmp = QueryParser::compareKeys(fType, a.data, a.length, b->data, b->length); + if (cmp != 0) + return cmp; + + // The attribute value is the same. Since the tree value is the tree + // node itself, we must not return 0, though. We consider a node-less + // key always less than an actual tree node with the same attribute + // value. + return -1; } int Compare(const Value* a, const Value* b) const { - return QueryParser::compareKeys(fType, a->data, a->length, b->data, + if (a == b) + return 0; + + int cmp = QueryParser::compareKeys(fType, a->data, a->length, b->data, b->length); + if (cmp != 0) + return cmp; + + return a < b ? -1 : 1; } private: