Skip to content

Commit 73fdb25

Browse files
committedAug 22, 2017
Safer handling of GDAL handles and feedback on success
1 parent ed42620 commit 73fdb25

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed
 

‎src/providers/ogr/qgsgeopackagedataitems.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,29 @@ bool QgsGeoPackageConnectionItem::handleDrop( const QMimeData *data, Qt::DropAct
423423
const char *args[] = { "-of", "gpkg", "-co", QStringLiteral( "RASTER_TABLE=%1" ).arg( u.name ).toUtf8().constData(), "-co", "APPEND_SUBDATASET=YES", nullptr };
424424
GDALTranslateOptions *psOptions = GDALTranslateOptionsNew( ( char ** )args, nullptr );
425425
GDALDatasetH hSrcDS = GDALOpen( u.uri.toUtf8().constData(), GA_ReadOnly );
426-
CPLErrorReset();
427-
GDALDatasetH hOutDS = GDALTranslate( mPath.toUtf8().constData(), hSrcDS, psOptions, NULL );
428-
if ( ! hOutDS )
426+
if ( ! hSrcDS )
429427
{
430-
importResults.append( tr( "Failed to import layer %1! See the message logs for details.\n\n" ).arg( u.name ) );
428+
importResults.append( tr( "Failed to open source layer %1! See the message logs for details.\n\n" ).arg( u.name ) );
431429
hasError = true;
432-
433430
}
434-
GDALClose( hSrcDS );
431+
else
432+
{
433+
CPLErrorReset();
434+
GDALDatasetH hOutDS = GDALTranslate( mPath.toUtf8().constData(), hSrcDS, psOptions, NULL );
435+
if ( ! hOutDS )
436+
{
437+
importResults.append( tr( "Failed to import layer %1! See the message logs for details.\n\n" ).arg( u.name ) );
438+
hasError = true;
439+
}
440+
else // All good!
441+
{
442+
GDALClose( hOutDS );
443+
// this is gross - TODO - find a way to get access to messageBar from data items
444+
QMessageBox::information( nullptr, tr( "Import to GeoPackage database" ), tr( "Import was successful." ) );
445+
refreshConnections();
446+
}
447+
GDALClose( hSrcDS );
448+
}
435449
GDALTranslateOptionsFree( psOptions );
436450
}
437451
} // do not overwrite

0 commit comments

Comments
 (0)
Please sign in to comment.