From d9f08d808d1ab6e7101467b242ab19fc539e00a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 10 Jan 2003 11:14:07 +0000 Subject: [PATCH] The empty string ("", length 0) will now be replaced with ("", length 1) in queries, to let the BPlusTree::Find() method search for it (there can't be any keys in the tree with length 0). That means that the query 'META:url=""' will now return all files where the attribute "META:url" is present but empty. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2401 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/Query.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Query.cpp b/src/add-ons/kernel/file_systems/bfs/Query.cpp index 6a3256eb0e..a848ecf75a 100644 --- a/src/add-ons/kernel/file_systems/bfs/Query.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Query.cpp @@ -383,7 +383,7 @@ matchString(char *pattern, char *string) invert = true; pattern++; } - + if (!pattern[0] || pattern[0] == ']') return MATCH_BAD_PATTERN; @@ -957,9 +957,18 @@ Equation::PrepareQuery(Volume */*volume*/, Index &index, TreeIterator **iterator } if (keySize == 0) { - if (fType == B_STRING_TYPE) + // B_STRING_TYPE doesn't have a fixed length, so it was set + // to 0 before - we compute the correct value here + if (fType == B_STRING_TYPE) { keySize = strlen(fValue.String); - else + + // The empty string is a special case - we normally don't check + // for the trailing null byte, in the case for the empty string + // we do it explicitly, because there can't be keys in the B+tree + // with a length of zero + if (keySize == 0) + keySize = 1; + } else RETURN_ERROR(B_ENTRY_NOT_FOUND); } @@ -970,7 +979,7 @@ Equation::PrepareQuery(Volume */*volume*/, Index &index, TreeIterator **iterator if (status == B_ENTRY_NOT_FOUND) return B_OK; } else { - status = (*iterator)->Find(Value(),keySize); + status = (*iterator)->Find(Value(), keySize); if (fOp == OP_EQUAL && !fIsPattern) return status; else if (status == B_ENTRY_NOT_FOUND