Skip to content

Commit

Permalink
Fixed NullPointerException upon cache reading (Issue #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
shundhammer committed Feb 1, 2016
1 parent d3299fb commit 5354e0b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/DirTreeCache.cpp
Expand Up @@ -229,13 +229,9 @@ CacheReader::~CacheReader()

if ( _toplevel )
{
logDebug() << "Finalizing recursive for " << _toplevel << endl;
finalizeRecursive( _toplevel );
_toplevel->finalizeAll();

if ( _toplevel->readState() == DirReading )
_toplevel->setReadState( DirCached );

logDebug() << "Sending read job finished for " << _toplevel << endl;
_tree->sendReadJobFinished( _toplevel );
}

emit finished();
Expand Down Expand Up @@ -414,7 +410,7 @@ void CacheReader::addItem()
// logDebug() << "Creating DirInfo for " << url << " with parent " << parent << endl;
DirInfo * dir = new DirInfo( _tree, parent, url,
mode, size, mtime );
dir->setReadState( DirCached );
dir->setReadState( DirReading );
_lastDir = dir;

if ( parent )
Expand Down Expand Up @@ -665,3 +661,25 @@ void CacheReader::killTrailingWhiteSpace( char * cptr )
*cptr-- = 0;
}


void CacheReader::finalizeRecursive( DirInfo * dir )
{
if ( dir->readState() != DirOnRequestOnly )
{
dir->setReadState( DirCached );
_tree->sendFinalizeLocal( dir );
dir->finalizeLocal();
_tree->sendReadJobFinished( dir );
}

FileInfo * child = dir->firstChild();

while ( child )
{
if ( child->isDirInfo() )
finalizeRecursive( child->toDirInfo() );

child = child->next();
}

}
7 changes: 7 additions & 0 deletions src/DirTreeCache.h
Expand Up @@ -219,6 +219,13 @@ namespace QDirStat
**/
int fieldsCount() const { return _fieldsCount; }

/**
* Recursively set the read status of all dirs from 'dir' on, send tree
* signals and finalize local (i.e. clean up empty or unneded dot
* entries).
**/
void finalizeRecursive( DirInfo * dir );


//
// Data members
Expand Down

0 comments on commit 5354e0b

Please sign in to comment.