Skip to content
Permalink
Browse files

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 05157f89a06dd65565770303c985a6d0d137ea98
Showing with 8 additions and 10 deletions.
  1. +6 −8 src/providers/ogr/qgsogrprovider.cpp
  2. +2 −2 src/providers/ogr/qgsogrprovider.h
@@ -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 ) ) );
@@ -176,7 +176,7 @@ void QgsOgrProvider::repack()
}
}

mDeletedFeatures = false;
mDataModified = false;
}
}

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

@@ -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;
}
@@ -2464,6 +2460,8 @@ bool QgsOgrProvider::syncToDisc()
}
}

mDataModified = true;

return true;
}

@@ -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;

0 comments on commit 05157f8

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