Skip to content

Commit

Permalink
[Browser] Fix invalid detection of OGR VRT by GDAL provider, and fix …
Browse files Browse the repository at this point in the history
…broken detection of OGR VRT (fixes #16806)
  • Loading branch information
rouault committed Oct 20, 2017
1 parent cc96f51 commit 4907180
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/providers/gdal/qgsgdaldataitems.cpp
Expand Up @@ -273,13 +273,13 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
// do not print errors, but write to debug
CPLPushErrorHandler( CPLQuietErrorHandler );
CPLErrorReset();
if ( ! GDALIdentifyDriver( path.toUtf8().constData(), nullptr ) )
GDALDriverH hDriver = GDALIdentifyDriver( path.toUtf8().constData(), nullptr );
CPLPopErrorHandler();
if ( !hDriver || GDALGetDriverShortName( hDriver ) == QLatin1String( "OGR_VRT" ) )
{
QgsDebugMsgLevel( "Skipping VRT file because root is not a GDAL VRT", 2 );
CPLPopErrorHandler();
return nullptr;
}
CPLPopErrorHandler();
}
// add the item
QStringList sublayers;
Expand Down
21 changes: 7 additions & 14 deletions src/providers/ogr/qgsogrdataitems.cpp
Expand Up @@ -592,21 +592,14 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
// if this is a VRT file make sure it is vector VRT to avoid duplicates
if ( suffix == QLatin1String( "vrt" ) )
{
GDALDriverH hDriver = GDALGetDriverByName( "OGR_VRT" );
if ( hDriver )
CPLPushErrorHandler( CPLQuietErrorHandler );
CPLErrorReset();
GDALDriverH hDriver = GDALIdentifyDriver( path.toUtf8().constData(), nullptr );
CPLPopErrorHandler();
if ( !hDriver || GDALGetDriverShortName( hDriver ) == QLatin1String( "VRT" ) )
{
// do not print errors, but write to debug
CPLPushErrorHandler( CPLQuietErrorHandler );
CPLErrorReset();
GDALDatasetH hDataSource = GDALOpenEx(
path.toLocal8Bit().constData(), GDAL_OF_VECTOR, nullptr, nullptr, nullptr );
CPLPopErrorHandler();
if ( ! hDataSource )
{
QgsDebugMsgLevel( "Skipping VRT file because root is not a OGR VRT", 2 );
return nullptr;
}
GDALClose( hDataSource );
QgsDebugMsgLevel( "Skipping VRT file because root is not a OGR VRT", 2 );
return nullptr;
}
}
// Handle collections
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -2403,7 +2403,7 @@ QString createFilters( const QString &type )
{
sDirectoryDrivers += QObject::tr( "U.S. Census TIGER/Line" ) + ",TIGER;";
}
else if ( driverName.startsWith( QLatin1String( "VRT" ) ) )
else if ( driverName.startsWith( QLatin1String( "OGR_VRT" ) ) )
{
sFileFilters += createFileFilter_( QObject::tr( "VRT - Virtual Datasource" ),
QStringLiteral( "*.vrt *.ovf" ) );
Expand Down

0 comments on commit 4907180

Please sign in to comment.