Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 b30f51a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -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";
}
Expand Down Expand Up @@ -6455,5 +6455,3 @@ QGISEXTERN QgsTransaction *createTransaction( const QString &connString )

return new QgsOgrTransaction( connString, ds );
}


28 changes: 28 additions & 0 deletions tests/src/python/test_provider_shapefile.py
Expand Up @@ -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 '''

Expand Down

0 comments on commit b30f51a

Please sign in to comment.