Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Repack() shapefiles on unload whenever they have been modified
Previous preconditions that would only repack them when features have been
deleted seems to not have covered everything.

Fix #11007
  • Loading branch information
m-kuhn committed Oct 20, 2014
1 parent 4e8c679 commit 05157f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -132,7 +132,7 @@ void QgsOgrProvider::repack()
QByteArray layerName = OGR_FD_GetName( OGR_L_GetLayerDefn( ogrOrigLayer ) );

// run REPACK on shape files
if ( mDeletedFeatures )
if ( mDataModified )
{
QByteArray sql = QByteArray( "REPACK " ) + layerName; // don't quote the layer name as it works with spaces in the name and won't work if the name is quoted
QgsDebugMsg( QString( "SQL: %1" ).arg( FROM8( sql ) ) );
Expand Down Expand Up @@ -176,7 +176,7 @@ void QgsOgrProvider::repack()
}
}

mDeletedFeatures = false;
mDataModified = false;
}
}

Expand Down Expand Up @@ -267,7 +267,7 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
, ogrDriver( 0 )
, valid( false )
, featuresCounted( -1 )
, mDeletedFeatures( false )
, mDataModified( false )
{
QgsCPLErrorHandler handler;

Expand Down Expand Up @@ -1378,11 +1378,7 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
bool returnvalue = true;
for ( QgsFeatureIds::const_iterator it = id.begin(); it != id.end(); ++it )
{
if ( deleteFeature( *it ) )
{
mDeletedFeatures = true;
}
else
if ( !deleteFeature( *it ) )
{
returnvalue = false;
}
Expand Down Expand Up @@ -2464,6 +2460,8 @@ bool QgsOgrProvider::syncToDisc()
}
}

mDataModified = true;

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/providers/ogr/qgsogrprovider.h
Expand Up @@ -329,8 +329,8 @@ class QgsOgrProvider : public QgsVectorDataProvider
int geomType;
long featuresCounted;

//! There are deleted feature - REPACK before creating a spatialindex
bool mDeletedFeatures;
//! Data has been modified - REPACK before creating a spatialindex
bool mDataModified;

mutable QStringList mSubLayerList;

Expand Down

0 comments on commit 05157f8

Please sign in to comment.