From ab47860c37a36b0eca0b65b94ebb3adc1c9fae54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 26 May 2003 01:45:09 +0000 Subject: [PATCH] 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 --- src/add-ons/kernel/file_systems/bfs/Index.cpp | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Index.cpp b/src/add-ons/kernel/file_systems/bfs/Index.cpp index bb5f6f1055..57fcd2940c 100644 --- a/src/add-ons/kernel/file_systems/bfs/Index.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Index.cpp @@ -46,14 +46,29 @@ 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) @@ -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