Skip to content

Commit

Permalink
Merge pull request OSGeo#5973 from rouault/fix_5970
Browse files Browse the repository at this point in the history
netCDF: fix 2 issues with netCDF 4.9.0 of msys2-mingw64 (fixes OSGeo#5970)
  • Loading branch information
rouault authored Jun 23, 2022
2 parents 832e983 + 50851fa commit 5f6ed12
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions frmts/netcdf/netcdfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@

#define ROTATED_POLE_VAR_NAME "rotated_pole"

// Detect netCDF 4.8
#ifdef NC_ENCZARR
// netCDF 4.8 switched to expecting filenames in UTF-8 on Windows
// But with netCDF 4.9 and https://github.com/Unidata/netcdf-c/pull/2277/,
// this is apparently back to expecting filenames in current codepage...
// Detect netCDF 4.8 with NC_ENCZARR
// Detect netCDF 4.9 with NC_NOATTCREORD
#if defined(NC_ENCZARR) && !defined(NC_NOATTCREORD)
#define NETCDF_USES_UTF8
#endif

Expand Down Expand Up @@ -9412,6 +9416,25 @@ netCDFDataset::CreateLL( const char *pszFilename,
}
#endif

#if defined(WIN32)
{
// Works around bug of msys2 netCDF 4.9.0 package where nc_create() crashes
VSIStatBuf sStat;
const char* pszDir = CPLGetDirname(osFilenameForNCCreate.c_str());
if( VSIStat(pszDir, &sStat) != 0 )
{
CPLError(CE_Failure, CPLE_OpenFailed,
"Unable to create netCDF file %s: non existing output directory",
pszFilename);
CPLReleaseMutex(hNCMutex); // Release mutex otherwise we'll deadlock
// with GDALDataset own mutex.
delete poDS;
CPLAcquireMutex(hNCMutex, 1000.0);
return nullptr;
}
}
#endif

int status = nc_create(osFilenameForNCCreate, poDS->nCreateMode, &(poDS->cdfid));

// Put into define mode.
Expand Down

0 comments on commit 5f6ed12

Please sign in to comment.