[WFS provider] Bugfix: call releaseCacheDirectory() if using a serialized feature writer stream

Funded by Planet
This commit is contained in:
Even Rouault 2019-10-09 14:58:14 +02:00 committed by Nyall Dawson
parent a8c5bb6854
commit 563a392bdd
3 changed files with 24 additions and 25 deletions

View File

@ -297,15 +297,13 @@ QgsBackgroundCachedFeatureIterator::~QgsBackgroundCachedFeatureIterator()
delete mWriterStream;
delete mWriterFile;
if ( !mWriterFilename.isEmpty() )
{
QFile::remove( mWriterFilename );
mShared->releaseCacheDirectory();
}
}
if ( mReaderStream )
{
delete mReaderStream;
delete mReaderFile;
if ( !mReaderFilename.isEmpty() )
QFile::remove( mReaderFilename );
}
cleanupReaderStreamAndFile();
}
void QgsBackgroundCachedFeatureIterator::connectSignals( QgsFeatureDownloader *downloader )
@ -363,6 +361,8 @@ void QgsBackgroundCachedFeatureIterator::featureReceivedSynchronous( const QVect
QgsDebugMsg( QStringLiteral( "Cannot open %1 for writing" ).arg( mWriterFilename ) );
delete mWriterFile;
mWriterFile = nullptr;
mWriterFilename.clear();
mShared->releaseCacheDirectory();
return;
}
mWriterFile->write( mWriterByteArray );
@ -554,16 +554,7 @@ bool QgsBackgroundCachedFeatureIterator::fetchFeature( QgsFeature &f )
}
// When the stream is finished, cleanup
delete mReaderStream;
mReaderStream = nullptr;
delete mReaderFile;
mReaderFile = nullptr;
mReaderByteArray.clear();
if ( !mReaderFilename.isEmpty() )
{
QFile::remove( mReaderFilename );
mReaderFilename.clear();
}
cleanupReaderStreamAndFile();
// And try again to check if there's a new output stream to read from
continue;
@ -593,11 +584,8 @@ bool QgsBackgroundCachedFeatureIterator::fetchFeature( QgsFeature &f )
}
}
bool QgsBackgroundCachedFeatureIterator::rewind()
void QgsBackgroundCachedFeatureIterator::cleanupReaderStreamAndFile()
{
if ( mClosed )
return false;
if ( mReaderStream )
{
delete mReaderStream;
@ -609,8 +597,17 @@ bool QgsBackgroundCachedFeatureIterator::rewind()
{
QFile::remove( mReaderFilename );
mReaderFilename.clear();
mShared->releaseCacheDirectory();
}
}
}
bool QgsBackgroundCachedFeatureIterator::rewind()
{
if ( mClosed )
return false;
cleanupReaderStreamAndFile();
QgsFeatureRequest requestCache;
int genCounter = mShared->getUpdatedCounter();

View File

@ -231,6 +231,8 @@ class QgsBackgroundCachedFeatureIterator : public QObject,
//! Copies feature attributes / geometry from srcFeature to dstFeature
void copyFeature( const QgsFeature &srcFeature, QgsFeature &dstFeature, bool srcIsCache );
void cleanupReaderStreamAndFile();
};

View File

@ -148,9 +148,12 @@ class QgsBackgroundCachedSharedData
//! Force an update of the feature count
void setFeatureCount( int featureCount );
//! Returns the name of temporary directory.
//! Returns the name of temporary directory. To be paired with releaseCacheDirectory()
QString acquireCacheDirectory();
//! To be called when a temporary file is removed from the directory
void releaseCacheDirectory();
//////// Pure virtual methods
//! Instantiate a new feature downloader implementation.
@ -189,9 +192,6 @@ class QgsBackgroundCachedSharedData
//! Should be called in the destructor of the implementation of this class !
void cleanup();
//! To be called when a temporary file is removed from the directory
void releaseCacheDirectory();
private:
//! Cache directory manager