Skip to content
Permalink
Browse files

Fixing potential infinite loop when rescanning file too early and

removing unnecessary multiple rescans as file is progressively updated
  • Loading branch information
ccrook committed Aug 12, 2013
1 parent 4ba9c47 commit 6b21b86b7769bc7738e6e63b6048739b1a4747da
@@ -77,6 +77,7 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider( QString uri )
, mUseSubsetIndex( false )
, mMaxInvalidLines( 50 )
, mShowInvalidLines( true )
, mRescanRequired( false )
, mCrs()
, mWkbType( QGis::WKBNoGeometry )
, mGeometryType( QGis::UnknownGeometry )
@@ -319,6 +320,7 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )

mLayerValid = false;
mValid = false;
mRescanRequired = false;

clearInvalidLines();

@@ -675,6 +677,7 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )

void QgsDelimitedTextProvider::rescanFile()
{
mRescanRequired = false;
resetIndexes();

bool buildSpatialIndex = mSpatialIndex != 0;
@@ -717,6 +720,7 @@ void QgsDelimitedTextProvider::rescanFile()
reportErrors( messages, false );
QgsDebugMsg( "Delimited text source invalid on rescan - missing geometry fields" );
mValid = false;
return;
}

// Reset the field columns
@@ -864,8 +868,9 @@ void QgsDelimitedTextProvider::resetStream()

QgsFeatureIterator QgsDelimitedTextProvider::getFeatures( const QgsFeatureRequest& request )
{
// If the file has become invalid, check that it is still invalid.
if ( mLayerValid && ! mValid ) rescanFile();
// If the file has become invalid, rescan to check that it is still invalid.
//
if ( (mLayerValid && ! mValid) || mRescanRequired ) rescanFile();

return QgsFeatureIterator( new QgsDelimitedTextFeatureIterator( this, request ) );
}
@@ -1050,9 +1055,13 @@ void QgsDelimitedTextProvider::setUriParameter( QString parameter, QString value

void QgsDelimitedTextProvider::onFileUpdated()
{
QStringList messages;
messages.append( tr( "The file has been updated by another application - reloading" ) );
reportErrors( messages, false );
if( ! mRescanRequired )
{
QStringList messages;
messages.append( tr( "The file has been updated by another application - reloading" ) );
reportErrors( messages, false );
mRescanRequired = true;
}

while ( !mActiveIterators.empty() )
{
@@ -1061,7 +1070,6 @@ void QgsDelimitedTextProvider::onFileUpdated()
it->close();
}

rescanFile();
}

bool QgsDelimitedTextProvider::nextFeature( QgsFeature& feature, QgsDelimitedTextFile *file, QgsDelimitedTextFeatureIterator *iterator )
@@ -1079,9 +1087,12 @@ bool QgsDelimitedTextProvider::nextFeature( QgsFeature& feature, QgsDelimitedTex
first = false;

// before we do anything else, assume that there's something wrong with
// the feature
// the feature. If the provider is not currently valid, then cannot return
// feature.

feature.setValid( false );
if( ! mValid ) break;

QgsDelimitedTextFile::Status status = file->nextRecord( tokens );
if ( status == QgsDelimitedTextFile::RecordEOF ) break;
if ( status != QgsDelimitedTextFile::RecordOk ) continue;
@@ -1250,6 +1261,7 @@ void QgsDelimitedTextProvider::fetchAttribute( QgsFeature& feature, int fieldIdx
// Return the extent of the layer
QgsRectangle QgsDelimitedTextProvider::extent()
{
if( mRescanRequired ) rescanFile();
return mExtent;
}

@@ -1266,6 +1278,7 @@ QGis::WkbType QgsDelimitedTextProvider::geometryType() const
*/
long QgsDelimitedTextProvider::featureCount() const
{
if( mRescanRequired ) const_cast<QgsDelimitedTextProvider *>(this)->rescanFile();
return mNumberFeatures;
}

@@ -296,6 +296,9 @@ class QgsDelimitedTextProvider : public QgsVectorDataProvider
//! Only want to show the invalid lines once to the user
bool mShowInvalidLines;

//! Record file updates, flags rescan required
bool mRescanRequired;

struct wkbPoint
{
unsigned char byteOrder;

0 comments on commit 6b21b86

Please sign in to comment.
You can’t perform that action at this time.