Skip to content

Commit

Permalink
HTTP driver: re-emit warnings/errors raised by underlying driver
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Nov 29, 2024
1 parent b618e64 commit 6dbdc70
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions frmts/http/httpdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* SPDX-License-Identifier: MIT
****************************************************************************/

#include "cpl_error_internal.h"
#include "cpl_string.h"
#include "cpl_http.h"
#include "gdal_frmts.h"
Expand Down Expand Up @@ -133,11 +134,27 @@ static GDALDataset *HTTPOpen(GDALOpenInfo *poOpenInfo)
/* Try opening this result as a gdaldataset. */
/* -------------------------------------------------------------------- */
/* suppress errors as not all drivers support /vsimem */
CPLPushErrorHandler(CPLQuietErrorHandler);
GDALDataset *poDS = (GDALDataset *)GDALOpenEx(
osResultFilename, poOpenInfo->nOpenFlags & ~GDAL_OF_SHARED,
poOpenInfo->papszAllowedDrivers, poOpenInfo->papszOpenOptions, nullptr);
CPLPopErrorHandler();

GDALDataset *poDS;
std::vector<CPLErrorHandlerAccumulatorStruct> aoErrors;
{
CPLErrorStateBackuper oBackuper(CPLQuietErrorHandler);
CPLInstallErrorHandlerAccumulator(aoErrors);
poDS = GDALDataset::Open(osResultFilename,
poOpenInfo->nOpenFlags & ~GDAL_OF_SHARED,
poOpenInfo->papszAllowedDrivers,
poOpenInfo->papszOpenOptions, nullptr);
CPLUninstallErrorHandlerAccumulator();
}

// Re-emit silenced errors if open was successful
if (poDS)
{
for (const auto &oError : aoErrors)
{
CPLError(oError.type, oError.no, "%s", oError.msg.c_str());
}
}

// The JP2OpenJPEG driver may need to reopen the file, hence this special
// behavior
Expand Down Expand Up @@ -171,10 +188,10 @@ static GDALDataset *HTTPOpen(GDALOpenInfo *poOpenInfo)
}
else
{
poDS = (GDALDataset *)GDALOpenEx(
osTempFilename, poOpenInfo->nOpenFlags & ~GDAL_OF_SHARED,
poOpenInfo->papszAllowedDrivers, poOpenInfo->papszOpenOptions,
nullptr);
poDS = GDALDataset::Open(osTempFilename,
poOpenInfo->nOpenFlags & ~GDAL_OF_SHARED,
poOpenInfo->papszAllowedDrivers,
poOpenInfo->papszOpenOptions, nullptr);
if (VSIUnlink(osTempFilename) != 0 && poDS != nullptr)
poDS->MarkSuppressOnClose(); /* VSIUnlink() may not work on
windows */
Expand Down

0 comments on commit 6dbdc70

Please sign in to comment.