Skip to content

Commit

Permalink
Keep it simple
Browse files Browse the repository at this point in the history
  • Loading branch information
shundhammer committed Feb 8, 2018
1 parent 72fc71e commit de19be3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 61 deletions.
70 changes: 29 additions & 41 deletions src/DirReadJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,29 @@ void DirReadJob::deletingChild( FileInfo *deletedChild )
bool DirReadJob::crossingFileSystems( DirInfo * parent, DirInfo * child )
{
if ( parent->device() == child->device() )
return false;
return false;

QString childDevice = device( child );
QString childDevice = device( child );
QString parentDevice = device( parent->findNearestMountPoint() );;

if ( parentDevice.isEmpty() )
parentDevice = _tree->device();
parentDevice = _tree->device();

bool crossing = true;

if ( ! parentDevice.isEmpty() && ! childDevice.isEmpty() )
crossing = parentDevice != childDevice;
crossing = parentDevice != childDevice;

if ( crossing )
{
logInfo() << "File system boundary at mount point " << child
<< " on device " << ( childDevice.isEmpty() ? "<unknown>" : childDevice )
<< endl;
logInfo() << "File system boundary at mount point " << child
<< " on device " << ( childDevice.isEmpty() ? "<unknown>" : childDevice )
<< endl;
}
else
{
logInfo() << "Mount point " << child
<< " is still on the same device " << childDevice << endl;
logInfo() << "Mount point " << child
<< " is still on the same device " << childDevice << endl;
}

return crossing;
Expand All @@ -127,10 +127,10 @@ QString DirReadJob::device( const DirInfo * dir ) const

if ( dir )
{
const MountPoint * mountPoint = MountPoints::findByPath( dir->url() );
const MountPoint * mountPoint = MountPoints::findByPath( dir->url() );

if ( mountPoint )
device = mountPoint->device();
if ( mountPoint )
device = mountPoint->device();
}

return device;
Expand Down Expand Up @@ -166,24 +166,24 @@ void LocalDirReadJob::startReading()

if ( access( dirName.toUtf8(), X_OK | R_OK ) != 0 )
{
ok = false;
logWarning() << "No permission to read directory " << dirName << endl;
ok = false;
logWarning() << "No permission to read directory " << dirName << endl;
_dir->setReadState( DirError );
finishReading( _dir );
}

if ( ok )
{
_diskDir = opendir( dirName.toUtf8() );

if ( ! _diskDir )
{
ok = false;
_dir->setReadState( DirError );
logWarning() << "opendir(" << dirName << ") failed" << endl;
// opendir() doesn't set 'errno' according to POSIX :-(
finishReading( _dir );
}
_diskDir = opendir( dirName.toUtf8() );

if ( ! _diskDir )
{
ok = false;
_dir->setReadState( DirError );
logWarning() << "opendir(" << dirName << ") failed" << endl;
// opendir() doesn't set 'errno' according to POSIX :-(
finishReading( _dir );
}
}

if ( ok )
Expand All @@ -198,7 +198,7 @@ void LocalDirReadJob::startReading()
entryName != ".." )
{
QString fullName = dirName == "/" ? "" : dirName; // Avoid leading // when in root dir
fullName += "/" + entryName;
fullName += "/" + entryName;

if ( lstat( fullName.toUtf8(), &statInfo ) == 0 ) // lstat() OK
{
Expand Down Expand Up @@ -382,7 +382,7 @@ FileInfo * LocalDirReadJob::stat( const QString & url,
}
else // lstat() failed
{
THROW( SysCallFailedException( "lstat", url ) );
THROW( SysCallFailedException( "lstat", url ) );
return 0; // NOTREACHED
}
}
Expand Down Expand Up @@ -488,18 +488,6 @@ void DirReadJobQueue::enqueue( DirReadJob * job )
_queue.append( job );
job->setQueue( this );

if ( job->tree() )
{
// Using a Qt::UniqueConnection to make sure we can simply set up
// this connection for each incoming read job. The tree might be
// different over the life time of the queue, so just setting up
// this connection once at the start might not be enough.

connect( job->tree(), SIGNAL( deletingChild ( FileInfo * ) ),
this, SLOT ( deletingChildNotify( FileInfo * ) ),
Qt::UniqueConnection );
}

if ( ! _timer.isActive() )
{
// logDebug() << "First job queued" << endl;
Expand Down Expand Up @@ -562,7 +550,7 @@ void DirReadJobQueue::killAll( DirInfo * subtree, DirReadJob * exceptJob )
if ( job->dir() && job->dir()->isInSubtree( subtree ) )
{
// logDebug() << "Killing read job " << job->dir() << endl;
++count;
++count;
it.remove();
delete job;
}
Expand Down Expand Up @@ -601,7 +589,7 @@ void DirReadJobQueue::deletingChildNotify( FileInfo * child )
{
if ( child && child->isDirInfo() )
{
logDebug() << "Killing all pending read jobs for " << child << endl;
killAll( child->toDirInfo() );
logDebug() << "Killing all pending read jobs for " << child << endl;
killAll( child->toDirInfo() );
}
}
19 changes: 11 additions & 8 deletions src/DirReadJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,17 @@ namespace QDirStat
void finished();


public slots:

/**
* Notification that a child node is about to be deleted from the
* outside (i.e., not from this ReadJobQueue), e.g. because of cleanup
* actions. This will remove all pending directory read jobs for that
* subtree from the job queue.
**/
void deletingChildNotify( FileInfo * child );


protected slots:

/**
Expand All @@ -402,14 +413,6 @@ namespace QDirStat
**/
void timeSlicedRead();

/**
* Notification that a child node is about to be deleted from the
* outside (i.e., not from this ReadJobQueue), e.g. because of cleanup
* actions. This will remove all pending directory read jobs for that
* subtree from the job queue.
**/
void deletingChildNotify( FileInfo * child );


protected:

Expand Down
27 changes: 15 additions & 12 deletions src/DirTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ using namespace QDirStat;
DirTree::DirTree()
: QObject()
{
_isBusy = false;
_isBusy = false;
_crossFileSystems = false;
_root = new DirInfo( this );
CHECK_NEW( _root );

connect( & _jobQueue, SIGNAL( finished() ),
this, SLOT ( slotFinished() ) );

connect( this, SIGNAL( deletingChild ( FileInfo * ) ),
& _jobQueue, SIGNAL( deletingChildNotify( FileInfo * ) ) );
}


Expand Down Expand Up @@ -138,8 +141,8 @@ void DirTree::refresh( const FileInfoSet & refreshSet )

foreach ( FileInfo * item, items )
{
// Need to check the magic number here again because a previous
// iteration step might have made the item invalid already
// Need to check the magic number here again because a previous
// iteration step might have made the item invalid already

if ( item && item->checkMagicNumber() )
{
Expand Down Expand Up @@ -173,14 +176,14 @@ void DirTree::refresh( DirInfo * subtree )

if ( ! subtree || ! subtree->parent() ) // Refresh all (from first toplevel)
{
try
{
startReading( QDir::cleanPath( firstToplevel()->url() ) );
}
catch ( const SysCallFailedException & ex )
{
CAUGHT( ex );
}
try
{
startReading( QDir::cleanPath( firstToplevel()->url() ) );
}
catch ( const SysCallFailedException & ex )
{
CAUGHT( ex );
}
}
else // Refresh subtree
{
Expand Down Expand Up @@ -273,7 +276,7 @@ void DirTree::deleteSubtree( FileInfo *subtree )
parent->parent()->setDotEntry( 0 );

delete parent;
parent = 0;
parent = 0;
}
}
else // no parent - this should never happen (?)
Expand Down

0 comments on commit de19be3

Please sign in to comment.