Skip to content

Commit 4907180

Browse files
committed
[Browser] Fix invalid detection of OGR VRT by GDAL provider, and fix broken detection of OGR VRT (fixes #16806)
1 parent cc96f51 commit 4907180

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

src/providers/gdal/qgsgdaldataitems.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,13 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
273273
// do not print errors, but write to debug
274274
CPLPushErrorHandler( CPLQuietErrorHandler );
275275
CPLErrorReset();
276-
if ( ! GDALIdentifyDriver( path.toUtf8().constData(), nullptr ) )
276+
GDALDriverH hDriver = GDALIdentifyDriver( path.toUtf8().constData(), nullptr );
277+
CPLPopErrorHandler();
278+
if ( !hDriver || GDALGetDriverShortName( hDriver ) == QLatin1String( "OGR_VRT" ) )
277279
{
278280
QgsDebugMsgLevel( "Skipping VRT file because root is not a GDAL VRT", 2 );
279-
CPLPopErrorHandler();
280281
return nullptr;
281282
}
282-
CPLPopErrorHandler();
283283
}
284284
// add the item
285285
QStringList sublayers;

src/providers/ogr/qgsogrdataitems.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -592,21 +592,14 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
592592
// if this is a VRT file make sure it is vector VRT to avoid duplicates
593593
if ( suffix == QLatin1String( "vrt" ) )
594594
{
595-
GDALDriverH hDriver = GDALGetDriverByName( "OGR_VRT" );
596-
if ( hDriver )
595+
CPLPushErrorHandler( CPLQuietErrorHandler );
596+
CPLErrorReset();
597+
GDALDriverH hDriver = GDALIdentifyDriver( path.toUtf8().constData(), nullptr );
598+
CPLPopErrorHandler();
599+
if ( !hDriver || GDALGetDriverShortName( hDriver ) == QLatin1String( "VRT" ) )
597600
{
598-
// do not print errors, but write to debug
599-
CPLPushErrorHandler( CPLQuietErrorHandler );
600-
CPLErrorReset();
601-
GDALDatasetH hDataSource = GDALOpenEx(
602-
path.toLocal8Bit().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr );
603-
CPLPopErrorHandler();
604-
if ( ! hDataSource )
605-
{
606-
QgsDebugMsgLevel( "Skipping VRT file because root is not a OGR VRT", 2 );
607-
return nullptr;
608-
}
609-
GDALClose( hDataSource );
601+
QgsDebugMsgLevel( "Skipping VRT file because root is not a OGR VRT", 2 );
602+
return nullptr;
610603
}
611604
}
612605
// Handle collections

src/providers/ogr/qgsogrprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2403,7 +2403,7 @@ QString createFilters( const QString &type )
24032403
{
24042404
sDirectoryDrivers += QObject::tr( "U.S. Census TIGER/Line" ) + ",TIGER;";
24052405
}
2406-
else if ( driverName.startsWith( QLatin1String( "VRT" ) ) )
2406+
else if ( driverName.startsWith( QLatin1String( "OGR_VRT" ) ) )
24072407
{
24082408
sFileFilters += createFileFilter_( QObject::tr( "VRT - Virtual Datasource" ),
24092409
QStringLiteral( "*.vrt *.ovf" ) );

0 commit comments

Comments
 (0)