Skip to content
Permalink
Browse files
[ogr] Don't report sublayers for unsupported zip child items
  • Loading branch information
nyalldawson authored and github-actions committed Nov 2, 2021
1 parent 850ee56 commit 73a014467bd22d192545e1d49a487f67a8996349
Showing with 44 additions and 1 deletion.
  1. +3 −1 src/core/providers/ogr/qgsogrprovidermetadata.cpp
  2. +41 −0 tests/src/python/test_provider_ogr.py
@@ -1107,7 +1107,9 @@ QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const

const QString path = uriParts.value( QStringLiteral( "path" ) ).toString();
const QFileInfo pathInfo( path );
const QString suffix = pathInfo.suffix().toLower();
const QString suffix = uriParts.value( QStringLiteral( "vsiSuffix" ) ).toString().isEmpty()
? pathInfo.suffix().toLower()
: QFileInfo( uriParts.value( QStringLiteral( "vsiSuffix" ) ).toString() ).suffix().toLower();
bool isOgrSupportedDirectory = pathInfo.isDir() && dirExtensions.contains( suffix );

bool forceDeepScanDir = false;
@@ -1600,6 +1600,27 @@ def test_provider_sublayer_details(self):
self.assertTrue(vl.isValid())
self.assertEqual(vl.wkbType(), QgsWkbTypes.Point)

# zip file layer vector, explicit file in zip
res = metadata.querySublayers('/vsizip/' + TEST_DATA_DIR + '/zip/points2.zip/points.shp')
self.assertEqual(len(res), 1)
self.assertEqual(res[0].layerNumber(), 0)
self.assertEqual(res[0].name(), "points.shp")
self.assertEqual(res[0].description(), '')
self.assertEqual(res[0].uri(), '/vsizip/' + TEST_DATA_DIR + "/zip/points2.zip/points.shp|layername=points")
self.assertEqual(res[0].providerKey(), "ogr")
self.assertEqual(res[0].type(), QgsMapLayerType.VectorLayer)
self.assertEqual(res[0].wkbType(), QgsWkbTypes.Point)
self.assertEqual(res[0].geometryColumnName(), '')
self.assertEqual(res[0].driverName(), 'ESRI Shapefile')
options = QgsProviderSublayerDetails.LayerOptions(QgsCoordinateTransformContext())
vl = res[0].toLayer(options)
self.assertTrue(vl.isValid())
self.assertEqual(vl.wkbType(), QgsWkbTypes.Point)

# zip file layer vector, explicit file in zip which is NOT a OGR supported source
res = metadata.querySublayers('/vsizip/' + TEST_DATA_DIR + '/zip/points2.zip/points.qml')
self.assertEqual(len(res), 0)

# multi-layer archive
res = metadata.querySublayers(os.path.join(TEST_DATA_DIR, 'zip', 'testtar.tgz'))
self.assertEqual(len(res), 2)
@@ -2310,6 +2331,26 @@ def test_provider_sublayer_details_fast_scan(self):
self.assertEqual(res[0].type(), QgsMapLayerType.VectorLayer)
self.assertFalse(res[0].skippedContainerScan())

# zip file layer vector, explicit file in zip
res = metadata.querySublayers('/vsizip/' + TEST_DATA_DIR + '/zip/points2.zip/points.shp', Qgis.SublayerQueryFlag.FastScan)
self.assertEqual(len(res), 1)
self.assertEqual(res[0].layerNumber(), 0)
self.assertEqual(res[0].name(), "points2") # this is wrong
self.assertEqual(res[0].description(), '')
self.assertEqual(res[0].uri(), '/vsizip/' + TEST_DATA_DIR + "/zip/points2.zip/points.shp")
self.assertEqual(res[0].providerKey(), "ogr")
self.assertEqual(res[0].type(), QgsMapLayerType.VectorLayer)
self.assertEqual(res[0].wkbType(), QgsWkbTypes.Unknown)
self.assertEqual(res[0].geometryColumnName(), '')
options = QgsProviderSublayerDetails.LayerOptions(QgsCoordinateTransformContext())
vl = res[0].toLayer(options)
self.assertTrue(vl.isValid())
self.assertEqual(vl.wkbType(), QgsWkbTypes.Point)

# zip file layer vector, explicit file in zip which is NOT a OGR supported source
res = metadata.querySublayers('/vsizip/' + TEST_DATA_DIR + '/zip/points2.zip/points.qml', Qgis.SublayerQueryFlag.FastScan)
self.assertEqual(len(res), 0)

def test_provider_sidecar_files_for_uri(self):
"""
Test retrieving sidecar files for uris

0 comments on commit 73a0144

Please sign in to comment.