Skip to content

Commit

Permalink
Fix to potential unterminated loop if a delimited text file is deleted
Browse files Browse the repository at this point in the history
Another try at fixing test cases with file watcher, don't work on some
platforms.
  • Loading branch information
ccrook committed Jun 1, 2013
1 parent a39b78b commit e87623d
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 169 deletions.
37 changes: 21 additions & 16 deletions src/providers/delimitedtext/qgsdelimitedtextfile.cpp
Expand Up @@ -82,6 +82,11 @@ void QgsDelimitedTextFile::close()
delete mWatcher;
mWatcher = 0;
}
mLineNumber = -1;
mRecordLineNumber = -1;
mRecordNumber = -1;
mMaxRecordNumber = -1;
mHoldCurrentRecord = false;
}

bool QgsDelimitedTextFile::open()
Expand All @@ -95,25 +100,24 @@ bool QgsDelimitedTextFile::open()
QgsDebugMsg( "Data file " + mFileName + " could not be opened" );
delete mFile;
mFile = 0;
return false;
}
mStream = new QTextStream( mFile );
if ( ! mEncoding.isEmpty() )
{
QTextCodec *codec = QTextCodec::codecForName( mEncoding.toAscii() );
mStream->setCodec( codec );
}
mMaxRecordNumber = -1;
mHoldCurrentRecord = false;
if ( mWatcher ) delete mWatcher;
if ( mUseWatcher )
if( mFile )
{
mWatcher = new QFileSystemWatcher( this );
mWatcher->addPath( mFileName );
connect( mWatcher, SIGNAL( fileChanged( QString ) ), this, SLOT( updateFile() ) );
mStream = new QTextStream( mFile );
if ( ! mEncoding.isEmpty() )
{
QTextCodec *codec = QTextCodec::codecForName( mEncoding.toAscii() );
mStream->setCodec( codec );
}
if ( mUseWatcher )
{
mWatcher = new QFileSystemWatcher( this );
mWatcher->addPath( mFileName );
connect( mWatcher, SIGNAL( fileChanged( QString ) ), this, SLOT( updateFile() ) );
}
}
}
return true;
return mFile != 0;
}

void QgsDelimitedTextFile::updateFile()
Expand Down Expand Up @@ -501,6 +505,7 @@ int QgsDelimitedTextFile::fieldIndex( QString name )

bool QgsDelimitedTextFile::setNextRecordId( long nextRecordId )
{
if( ! mFile ) return false;
mHoldCurrentRecord = nextRecordId == mRecordLineNumber;
if ( mHoldCurrentRecord ) return true;
return setNextLineNumber( nextRecordId );
Expand All @@ -524,7 +529,7 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::nextRecord( QStringList &reco
// Find the first non-blank line to read
QString buffer;
status = nextLine( buffer, true );
if ( status != RecordOk ) return status;
if ( status != RecordOk ) return RecordEOF;

mCurrentRecord.clear();
mRecordLineNumber = mLineNumber;
Expand Down

0 comments on commit e87623d

Please sign in to comment.