Index::SetTo() now sets fName even if the index initialization failed (for

whatever reason).
Index::Update() is now allowed to be called for those indices - in this case
it will just update all live queries.
Added some comments.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3329 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2003-05-26 01:45:09 +00:00
parent 09ed3db89a
commit ab47860c37

View File

@ -46,15 +46,30 @@ Index::Unset()
put_vnode(fVolume->ID(), fNode->ID());
fNode = NULL;
fName = NULL;
}
/** Sets the index to specified one. Returns an error if the index could
* not be found or initialized.
* Note, Index::Update() may be called on the object even if this method
* failed previously. In this case, it will only update live queries for
* the updated attribute.
*/
status_t
Index::SetTo(const char *name)
{
// remove the old node, if the index is set for the second time
Unset();
fName = name;
// only stores the pointer, so it assumes that it will stay constant
// in further comparisons (currently only used in Index::Update())
// Note, the name is saved even if the index couldn't be initialized!
// This is used to optimize Index::Update() in case there is no index
Inode *indices = fVolume->IndicesNode();
if (indices == NULL)
return B_ENTRY_NOT_FOUND;
@ -76,14 +91,16 @@ Index::SetTo(const char *name)
put_vnode(fVolume->ID(), id);
return B_ERROR;
}
fName = name;
// only stores the pointer, so it assumes that it will stay constant
// in further comparisons (currently only used in Index::Update())
return B_OK;
}
/** Returns a standard type code for the stat() index type codes. Returns
* zero if the type is not known (can only happen if the mode field is
* corrupted somehow or not that of an index).
*/
uint32
Index::Type()
{
@ -217,7 +234,8 @@ Index::Update(Transaction *transaction, const char *name, int32 type, const uint
fVolume->UpdateLiveQueries(inode, name, type, oldKey, oldLength, newKey, newLength);
status_t status;
if (name != fName && (status = SetTo(name)) < B_OK)
if (((name != fName || strcmp(name, fName)) && (status = SetTo(name)) < B_OK)
|| fNode == NULL)
return B_BAD_INDEX;
// now that we have the type, check again for equality