MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / AddItem

Method AddItem

src/db/blockrecordarray.cpp:231–327  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// AddItem //////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

229// AddItem
230///////////////////////////////////////////////////////////////////////////////
231int cBlockRecordArray::AddItem(int8* pData, int dataSize, int mainIndex) //throw (eArchive)
232{
233 // make ourselves initialized, if we are not right now...
234 //
235 if (!Initialized())
236 {
237 InitForExistingBlock();
238 }
239
240
241 ASSERT(dataSize <= GetAvailableSpace());
242 ASSERT(GetNumItems() <= MAX_RECORDS);
243 ASSERT(dataSize > 0); // I am not sure if this is the right thing to do !
244 ASSERT(mpBlockFile != 0);
245 ASSERT(mainIndex != INVALID_INDEX);
246 ASSERT(Initialized());
247#ifdef _BLOCKFILE_DEBUG
248 AssertValid();
249 mpBlockFile->AssertValid();
250#endif
251 cDebug d("cBlockRecordArray::AddItem");
252 d.TraceDetail("Entering... adding item of size %d to block %d\n", dataSize, mBlockNum);
253 //
254 // get the block we need and a reference into the index array....
255 //
256 cBlockFile::Block* pBlock = mpBlockFile->GetBlock(mBlockNum);
257 tIndexArray& indexArray = util_GetIndexArray(pBlock);
258 //
259 // find an unused entry to put the item into...
260 //
261 tRecordIndex* pIndex = indexArray.maRecordIndex;
262 int newIndex = 0;
263 for (; newIndex < mNumItems; newIndex++, pIndex++)
264 {
265 if (pIndex->GetMainIndex() == INVALID_INDEX)
266 break;
267 }
268 d.TraceDetail("Adding new item to index %d (max index + 1 = %d)\n", newIndex, mNumItems);
269 // write the data we know for sure at this point...
270 //
271 pIndex->SetMainIndex(mainIndex);
272 pBlock->SetDirty();
273 //
274 // calculate the offset for the new data
275 //
276 int prevOffset = (newIndex == 0 ? 0 : indexArray.maRecordIndex[newIndex - 1].GetOffset());
277 pIndex->SetOffset(prevOffset + dataSize);
278
279 if (newIndex == mNumItems)
280 {
281 //
282 // increment the max number of indexes...
283 //
284 mNumItems++;
285 indexArray.maRecordIndex[mNumItems].SetOffset(-1);
286 indexArray.maRecordIndex[mNumItems].SetMainIndex(INVALID_INDEX);
287 }
288 else

Callers

nothing calls this directly

Calls 9

util_OffsetToAddrFunction · 0.85
GetMainIndexMethod · 0.80
SetMainIndexMethod · 0.80
SetDirtyMethod · 0.80
GetOffsetMethod · 0.80
SetOffsetMethod · 0.80
TraceDetailMethod · 0.60
AssertValidMethod · 0.45
GetBlockMethod · 0.45

Tested by

no test coverage detected