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

Method SeekToDirectory

src/tw/dbdatasource.cpp:323–403  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// SeekToDirectory //////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

321// SeekToDirectory
322///////////////////////////////////////////////////////////////////////////////
323bool cDbDataSourceIter::SeekToDirectory(const cFCOName& parentName, bool bCreate)
324{
325 cDebug d("cDbDataSourceIter::SeekToDirectory");
326 //
327 // the first task is to ascend until we are in a directory that we can descend into to
328 // reach parentName...
329 //
330 cFCOName curParent = GetParentName();
331 d.TraceDebug(
332 _T("Entering... Seeking to %s (cwd = %s)\n"), parentName.AsString().c_str(), curParent.AsString().c_str());
333 int ascendCount;
334 switch (curParent.GetRelationship(parentName))
335 {
336 case cFCOName::REL_BELOW:
337 //
338 // we must ascend...
339 //
340 ascendCount = curParent.GetSize() - parentName.GetSize();
341 d.TraceDetail(_T("\tAscending %d times...\n"), ascendCount);
342 ASSERT(ascendCount > 0);
343 for (; ascendCount > 0; ascendCount--)
344 Ascend();
345 break;
346 case cFCOName::REL_ABOVE:
347 //
348 // we are above the needed directory; nothing else to do here...
349 //
350 d.TraceDetail(_T("\tAbove; not ascending...\n"));
351 break;
352 case cFCOName::REL_EQUAL:
353 //
354 // we need to do nothing else here...
355 //
356 d.TraceDetail(_T("\tEqual; doing nothing...\n"));
357 SeekBegin();
358 return true;
359 case cFCOName::REL_UNRELATED:
360 //
361 // we have to go all the way to the root...
362 //
363 d.TraceDetail(_T("\tUnrelated; seeking to root...\n"));
364 SeekToRoot();
365 break;
366 default:
367 // unreachable
368 ASSERT(false);
369 return false;
370 }
371
372 curParent = GetParentName();
373 if (parentName.GetSize() == curParent.GetSize())
374 return true;
375 //
376 // now we will descend to the parent directory we are interested in...
377 //
378 cFCOName::iterator i(parentName);
379 i.SeekTo(curParent.GetSize());
380 for (; (!i.Done()); i.Next())

Callers

nothing calls this directly

Calls 14

c_strMethod · 0.80
CreateEntryMethod · 0.80
CreateChildArrayMethod · 0.80
TraceDebugMethod · 0.60
TraceDetailMethod · 0.60
AsStringMethod · 0.45
GetRelationshipMethod · 0.45
GetSizeMethod · 0.45
SeekToMethod · 0.45
DoneMethod · 0.45
NextMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected