Skip to content

Commit

Permalink
backport GDAL #8788 (#43)
Browse files Browse the repository at this point in the history
* backport GDAL #8788

* add testing Dockerfile
  • Loading branch information
gillins authored Nov 23, 2023
1 parent 796fdea commit 7f17d7c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM ubuntu:22.04

# Needed in case tzdata gets upgraded
ENV TZ=Australia/Brisbane
ARG DEBIAN_FRONTEND=noninteractive

# Use Aussie mirrors
RUN sed -i 's/http:\/\/archive./http:\/\/au.archive./g' /etc/apt/sources.list

# Update Ubuntu software stack and install base GDAL stack
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y wget g++ cmake libhdf5-dev libgdal-dev gdal-bin

RUN apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY . /tmp/kealib
RUN cd /tmp/kealib \
&& mkdir build \
&& cd build \
&& cmake -D LIBKEA_WITH_GDAL=ON .. \
&& make \
&& make install \
&& cd ../.. \
&& rm -rf kealib

ENV LD_LIBRARY_PATH=/usr/local/lib
ENV GDAL_DRIVER_PATH=/usr/local/lib/gdalplugins

RUN gdal_translate --formats | grep KEA
30 changes: 30 additions & 0 deletions gdal/keadataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "keacopy.h"

#include "libkea/KEACommon.h"
#include "cpl_vsi_virtual.h"

// Function for converting a libkea type into a GDAL type
GDALDataType KEA_to_GDAL_Type( kealib::KEADataType ekeaType )
Expand Down Expand Up @@ -166,6 +167,14 @@ GDALDataset *KEADataset::Open( GDALOpenInfo * poOpenInfo )
poOpenInfo->pszFilename, e.what() );
return nullptr;
}
catch (...)
{
// was a problem - can't be a valid file
CPLError(CE_Failure, CPLE_OpenFailed,
"Attempt to open file `%s' failed. Error: unknown\n",
poOpenInfo->pszFilename);
return nullptr;
}
}
else
{
Expand Down Expand Up @@ -208,6 +217,20 @@ GDALDataset *KEADataset::Create( const char * pszFilename,
"Attempt to create file `%s' failed. Invalid creation option(s)\n", pszFilename);
return nullptr;
}

// This helps avoiding issues with H5File handles in a bad state, that
// may cause crashes at process termination
// Cf https://github.com/OSGeo/gdal/issues/8743
if (VSIFileManager::GetHandler(pszFilename) !=
VSIFileManager::GetHandler(""))
{
CPLError(CE_Failure, CPLE_OpenFailed,
"Attempt to create file `%s' failed. /vsi file systems not "
"supported\n",
pszFilename);
return nullptr;
}

// process any creation options in papszParmList
// default value
unsigned int nimageblockSize = kealib::KEA_IMAGE_CHUNK_SIZE;
Expand Down Expand Up @@ -296,6 +319,13 @@ GDALDataset *KEADataset::Create( const char * pszFilename,
pszFilename, e.what() );
return nullptr;
}
catch (...)
{
CPLError(CE_Failure, CPLE_OpenFailed,
"Attempt to create file `%s' failed. Error: unknown\n",
pszFilename);
return nullptr;
}
}

GDALDataset *KEADataset::CreateCopy( const char * pszFilename, GDALDataset *pSrcDs,
Expand Down

0 comments on commit 7f17d7c

Please sign in to comment.