| 1315 | } |
| 1316 | |
| 1317 | DirectoryNode* StreamIndexedIO::Node::directoryChild( const IndexedIO::EntryID &name ) const |
| 1318 | { |
| 1319 | Index::MutexLock lock; |
| 1320 | m_idx->lockDirectory( lock, m_node ); |
| 1321 | |
| 1322 | DirectoryNode::ChildMap::iterator it = m_node->findChild( name ); |
| 1323 | if ( it != m_node->children().end() ) |
| 1324 | { |
| 1325 | if ( (*it)->nodeType() == NodeBase::Directory ) |
| 1326 | { |
| 1327 | DirectoryNode *dir = static_cast< DirectoryNode *>( (*it) ); |
| 1328 | |
| 1329 | if ( dir->subindex() == DirectoryNode::SavedSubIndex ) |
| 1330 | { |
| 1331 | if ( m_node->subindexChildren() ) |
| 1332 | { |
| 1333 | lock.release(); /// we will not change the children dictionary, so we release the lock! |
| 1334 | } |
| 1335 | |
| 1336 | // this can occur when the user flushed a directory and right after tries to access it. |
| 1337 | m_idx->readNodeFromSubIndex( dir ); |
| 1338 | } |
| 1339 | return dir; |
| 1340 | } |
| 1341 | else if ( (*it)->nodeType() == NodeBase::SubIndex ) |
| 1342 | { |
| 1343 | SubIndexNode *subIndex = static_cast< SubIndexNode *>( (*it) ); |
| 1344 | |
| 1345 | // build a Directory that knows it's flushed to a subindex. |
| 1346 | DirectoryNode *newDir = new DirectoryNode( subIndex, m_node ); |
| 1347 | |
| 1348 | lock.release(); /// we release the lock while loading data.. |
| 1349 | |
| 1350 | m_idx->readNodeFromSubIndex( newDir ); |
| 1351 | |
| 1352 | // now that we loaded the whole thing, lock our Index for writing |
| 1353 | m_idx->lockDirectory( lock, m_node, true ); |
| 1354 | |
| 1355 | // there's a chance that someone else already replaced the pointer... |
| 1356 | if ( (*it)->nodeType() == NodeBase::Directory ) |
| 1357 | { |
| 1358 | lock.release(); /// we release the lock because we won't change the children anyways.. |
| 1359 | NodeBase::destroy( newDir ); |
| 1360 | return static_cast< DirectoryNode *>(*it); |
| 1361 | } |
| 1362 | |
| 1363 | // replace SubIndex by Directory node. |
| 1364 | (*it) = newDir; |
| 1365 | |
| 1366 | // and now we are ok to delete the SubIndexNode.. |
| 1367 | delete subIndex; |
| 1368 | |
| 1369 | return newDir; |
| 1370 | } |
| 1371 | } |
| 1372 | return nullptr; |
| 1373 | } |
| 1374 |
no test coverage detected