Skip to content
Permalink
Browse files

Safer handling of GDAL handles and feedback on success

  • Loading branch information
elpaso committed Aug 22, 2017
1 parent ed42620 commit 73fdb25449f5092fc3ed1c718ea443fd9ffdc846
Showing with 20 additions and 6 deletions.
  1. +20 −6 src/providers/ogr/qgsgeopackagedataitems.cpp
@@ -423,15 +423,29 @@ bool QgsGeoPackageConnectionItem::handleDrop( const QMimeData *data, Qt::DropAct
const char *args[] = { "-of", "gpkg", "-co", QStringLiteral( "RASTER_TABLE=%1" ).arg( u.name ).toUtf8().constData(), "-co", "APPEND_SUBDATASET=YES", nullptr };
GDALTranslateOptions *psOptions = GDALTranslateOptionsNew( ( char ** )args, nullptr );
GDALDatasetH hSrcDS = GDALOpen( u.uri.toUtf8().constData(), GA_ReadOnly );
CPLErrorReset();
GDALDatasetH hOutDS = GDALTranslate( mPath.toUtf8().constData(), hSrcDS, psOptions, NULL );
if ( ! hOutDS )
if ( ! hSrcDS )
{
importResults.append( tr( "Failed to import layer %1! See the message logs for details.\n\n" ).arg( u.name ) );
importResults.append( tr( "Failed to open source layer %1! See the message logs for details.\n\n" ).arg( u.name ) );
hasError = true;

}
GDALClose( hSrcDS );
else
{
CPLErrorReset();
GDALDatasetH hOutDS = GDALTranslate( mPath.toUtf8().constData(), hSrcDS, psOptions, NULL );
if ( ! hOutDS )
{
importResults.append( tr( "Failed to import layer %1! See the message logs for details.\n\n" ).arg( u.name ) );
hasError = true;
}
else // All good!
{
GDALClose( hOutDS );
// this is gross - TODO - find a way to get access to messageBar from data items
QMessageBox::information( nullptr, tr( "Import to GeoPackage database" ), tr( "Import was successful." ) );
refreshConnections();
}
GDALClose( hSrcDS );
}
GDALTranslateOptionsFree( psOptions );
}
} // do not overwrite

0 comments on commit 73fdb25

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