Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VectorFileWriter/OGR provider: workaround GDAL 3.1.x bug regarding XLSX and ODS creation #38837

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/core/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4340,6 +4340,18 @@ void QgsOgrProviderUtils::GDALCloseWrapper( GDALDatasetH hDS )
GDALClose( hDS );
}
}

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,1,0) && GDAL_VERSION_NUM <= GDAL_COMPUTE_VERSION(3,1,3)
else if ( mGDALDriverName == QLatin1String( "XLSX" ) ||
mGDALDriverName == QLatin1String( "ODS" ) )
{
// Workaround bug in GDAL 3.1.0 to 3.1.3 that creates XLSX and ODS files incompatible with LibreOffice due to use of ZIP64
CPLSetThreadLocalConfigOption( "CPL_CREATE_ZIP64", "NO" );
GDALClose( hDS );
CPLSetThreadLocalConfigOption( "CPL_CREATE_ZIP64", nullptr );
}
#endif

else
{
GDALClose( hDS );
Expand Down Expand Up @@ -6186,7 +6198,25 @@ OGRErr QgsOgrLayer::RollbackTransaction()
OGRErr QgsOgrLayer::SyncToDisk()
{
QMutexLocker locker( &ds->mutex );
return OGR_L_SyncToDisk( hLayer );

OGRErr eErr;
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,1,0) && GDAL_VERSION_NUM <= GDAL_COMPUTE_VERSION(3,1,3)
// Workaround bug in GDAL 3.1.0 to 3.1.3 that creates XLSX and ODS files incompatible with LibreOffice due to use of ZIP64
QString drvName = GDALGetDriverShortName( GDALGetDatasetDriver( ds->hDS ) );
if ( drvName == QLatin1String( "XLSX" ) ||
drvName == QLatin1String( "ODS" ) )
{
CPLSetThreadLocalConfigOption( "CPL_CREATE_ZIP64", "NO" );
eErr = OGR_L_SyncToDisk( hLayer );
CPLSetThreadLocalConfigOption( "CPL_CREATE_ZIP64", nullptr );
}
else
#endif
{
eErr = OGR_L_SyncToDisk( hLayer );
}

return eErr;
}

void QgsOgrLayer::ExecuteSQLNoReturn( const QByteArray &sql )
Expand Down
15 changes: 15 additions & 0 deletions src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,21 @@ QgsVectorFileWriter::~QgsVectorFileWriter()
}
}

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,1,0) && GDAL_VERSION_NUM <= GDAL_COMPUTE_VERSION(3,1,3)
if ( mDS )
{
// Workaround bug in GDAL 3.1.0 to 3.1.3 that creates XLSX and ODS files incompatible with LibreOffice due to use of ZIP64
QString drvName = GDALGetDriverShortName( GDALGetDatasetDriver( mDS.get() ) );
if ( drvName == QLatin1String( "XLSX" ) ||
drvName == QLatin1String( "ODS" ) )
{
CPLSetThreadLocalConfigOption( "CPL_CREATE_ZIP64", "NO" );
mDS.reset();
CPLSetThreadLocalConfigOption( "CPL_CREATE_ZIP64", nullptr );
}
}
#endif

mDS.reset();

if ( mOgrRef )
Expand Down