Skip to content
Permalink
Browse files

fixes #18421 : Keep options AUTO_REPACK=OFF when reloading data in og…

…r provider
  • Loading branch information
troopa81 authored and nyalldawson committed Feb 20, 2019
1 parent 82e189e commit b30f51ab7102967e4103d8c67a45049e599ee4ec
Showing with 29 additions and 3 deletions.
  1. +1 −3 src/providers/ogr/qgsogrprovider.cpp
  2. +28 −0 tests/src/python/test_provider_shapefile.py
@@ -4121,7 +4121,7 @@ void QgsOgrProvider::open( OpenMode mode )
if ( !openReadOnly )
{
QStringList options;
if ( mode == OpenModeForceUpdateRepackOff )
if ( mode == OpenModeForceUpdateRepackOff || ( mDeferRepack && OpenModeSameAsCurrent ) )
{
options << "AUTO_REPACK=OFF";
}
@@ -6455,5 +6455,3 @@ QGISEXTERN QgsTransaction *createTransaction( const QString &connString )

return new QgsOgrTransaction( connString, ds );
}


@@ -484,6 +484,34 @@ def testDeleteShapes(self):

vl = None

def testDontRepackOnReload(self):
''' Test fix for #18421 '''

tmpdir = tempfile.mkdtemp()
self.dirs_to_cleanup.append(tmpdir)
srcpath = os.path.join(TEST_DATA_DIR, 'provider')
for file in glob.glob(os.path.join(srcpath, 'shapefile.*')):
shutil.copy(os.path.join(srcpath, file), tmpdir)
datasource = os.path.join(tmpdir, 'shapefile.shp')

vl = QgsVectorLayer('{}|layerid=0'.format(datasource), 'test', 'ogr')
feature_count = vl.featureCount()
# Start an iterator that will open a new connection
iterator = vl.getFeatures()
next(iterator)

# Delete another feature while in update mode
vl.dataProvider().enterUpdateMode()
vl.dataProvider().reloadData()
vl.dataProvider().deleteFeatures([0])

# Test that repacking has not been done (since in update mode)
ds = osgeo.ogr.Open(datasource)
self.assertTrue(ds.GetLayer(0).GetFeatureCount() == feature_count)
ds = None

vl = None

def testRepackUnderFileLocks(self):
''' Test fix for #15570 and #15393 '''

0 comments on commit b30f51a

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