Skip to content

Commit

Permalink
Fix a whole lot of drivers to error out when trying to open a read-on…
Browse files Browse the repository at this point in the history
…ly dataset in update mode (#3147)

git-svn-id: https://svn.osgeo.org/gdal/trunk/gdal@17664 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
rouault committed Sep 21, 2009
1 parent a09084e commit a4d23f6
Show file tree
Hide file tree
Showing 48 changed files with 595 additions and 45 deletions.
11 changes: 11 additions & 0 deletions frmts/aigrid/aigdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,17 @@ GDALDataset *AIGDataset::Open( GDALOpenInfo * poOpenInfo )
}

/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
AIGClose(psInfo);
CPLError( CE_Failure, CPLE_NotSupported,
"The AIG driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
AIGDataset *poDS;
Expand Down
10 changes: 10 additions & 0 deletions frmts/airsar/airsardataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,16 @@ GDALDataset *AirSARDataset::Open( GDALOpenInfo * poOpenInfo )
return NULL;

/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The AIRSAR driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
AirSARDataset *poDS;
Expand Down
12 changes: 12 additions & 0 deletions frmts/blx/blxdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ GDALDataset *BLXDataset::Open( GDALOpenInfo * poOpenInfo )
poDS->nBands = 1;
poDS->papoOverviewDS[i]->SetBand(1, new BLXRasterBand( poDS->papoOverviewDS[i], 1, i+1));
}

/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
delete poDS;
CPLError( CE_Failure, CPLE_NotSupported,
"The BLX driver does not support update access to existing"
" datasets.\n" );
return NULL;
}

return( poDS );
}
Expand Down
8 changes: 8 additions & 0 deletions frmts/bsb/bsbdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,14 @@ GDALDataset *BSBDataset::Open( GDALOpenInfo * poOpenInfo )
pszRA = strstr((const char*)poOpenInfo->pabyHeader + i, "[JF");
if (pszRA == NULL || pszRA - ((const char*)poOpenInfo->pabyHeader + i) > 100 )
return NULL;

if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The BSB driver does not support update access to existing"
" datasets.\n" );
return NULL;
}

/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
Expand Down
11 changes: 11 additions & 0 deletions frmts/ceos/ceosdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ GDALDataset *CEOSDataset::Open( GDALOpenInfo * poOpenInfo )
return( NULL );

/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
CEOSClose(psCEOS);
CPLError( CE_Failure, CPLE_NotSupported,
"The CEOS driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
CEOSDataset *poDS;
Expand Down
12 changes: 11 additions & 1 deletion frmts/ceos2/sar_ceosdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,17 @@ GDALDataset *SAR_CEOSDataset::Open( GDALOpenInfo * poOpenInfo )
// value appears to be little endian.
if( poOpenInfo->pabyHeader[0] != 0 )
return NULL;


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The SAR_CEOS driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
Expand Down
12 changes: 11 additions & 1 deletion frmts/coasp/coasp_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,17 @@ GDALDataset *COASPDataset::Open( GDALOpenInfo *poOpenInfo )
{
if (!COASPDataset::Identify(poOpenInfo))
return NULL;


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The COASP driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
/* Create a fresh dataset for us to work with */
COASPDataset *poDS;
poDS = new COASPDataset();
Expand Down
12 changes: 11 additions & 1 deletion frmts/cosar/cosar_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ GDALDataset *COSARDataset::Open( GDALOpenInfo * pOpenInfo ) {
if (!EQUALN((char *)pOpenInfo->pabyHeader+MAGIC1_OFFSET, "CSAR",4))
return NULL;


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( pOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The COSAR driver does not support update access to existing"
" datasets.\n" );
return NULL;
}

/* this is a cosar dataset */
COSARDataset *pDS;
pDS = new COSARDataset();
Expand Down
12 changes: 11 additions & 1 deletion frmts/dimap/dimapdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,17 @@ GDALDataset *DIMAPDataset::Open( GDALOpenInfo * poOpenInfo )
{
if( !Identify( poOpenInfo ) )
return NULL;


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The DIMAP driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Get the metadata filename. */
/* -------------------------------------------------------------------- */
Expand Down
14 changes: 13 additions & 1 deletion frmts/dods/dodsdataset2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,19 @@ DODSDataset::Open(GDALOpenInfo *poOpenInfo)
}

CSLDestroy(papszVarConstraintList);


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poDS != NULL && poOpenInfo->eAccess == GA_Update )
{
delete poDS;
CPLError( CE_Failure, CPLE_NotSupported,
"The DODS driver does not support update access to existing"
" datasets.\n" );
return NULL;
}

return poDS;
}

Expand Down
22 changes: 21 additions & 1 deletion frmts/ecw/ecwdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,14 @@ GDALDataset *ECWDataset::Open( GDALOpenInfo * poOpenInfo )
}
}

if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The DIMAP driver does not support update access to existing"
" datasets.\n" );
return NULL;
}

/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -1314,7 +1322,19 @@ GDALDataset *ECWDataset::Open( GDALOpenInfo * poOpenInfo )
/* -------------------------------------------------------------------- */
poDS->SetDescription( poOpenInfo->pszFilename );
poDS->TryLoadXML();


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
delete poDS;
CPLError( CE_Failure, CPLE_NotSupported,
"The ECW driver does not support update access to existing"
" datasets.\n" );
return NULL;
}

return( poDS );
}

Expand Down
13 changes: 12 additions & 1 deletion frmts/envisat/envisatdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,18 @@ GDALDataset *EnvisatDataset::Open( GDALOpenInfo * poOpenInfo )
if( EQUAL(pszDSType,"M") )
break;
}


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
EnvisatFile_Close( hEnvisatFile );
CPLError( CE_Failure, CPLE_NotSupported,
"The ENVISAT driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
Expand Down
12 changes: 11 additions & 1 deletion frmts/gff/gff_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,17 @@ GDALDataset *GFFDataset::Open( GDALOpenInfo *poOpenInfo )
if (!GFFDataset::Identify(poOpenInfo))
return NULL;


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The GFF driver does not support update access to existing"
" datasets.\n" );
return NULL;
}

GFFDataset *poDS;
poDS = new GFFDataset();
/* Steal the file pointer */
Expand Down
14 changes: 13 additions & 1 deletion frmts/grass/grass57dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,19 @@ GDALDataset *GRASSDataset::Open( GDALOpenInfo * poOpenInfo )

CSLDestroy(papszCells);
CSLDestroy(papszMapsets);


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
delete poDS;
CPLError( CE_Failure, CPLE_NotSupported,
"The GRASS driver does not support update access to existing"
" datasets.\n" );
return NULL;
}

return poDS;
}

Expand Down
14 changes: 13 additions & 1 deletion frmts/grass/grassdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,19 @@ GDALDataset *GRASSDataset::Open( GDALOpenInfo * poOpenInfo )
papszMapsets[iBand],
papszCells[iBand] ) );
}


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
delete poDS;
CPLError( CE_Failure, CPLE_NotSupported,
"The GRASS driver does not support update access to existing"
" datasets.\n" );
return NULL;
}

return poDS;
}

Expand Down
10 changes: 10 additions & 0 deletions frmts/grib/gribdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ GDALDataset *GRIBDataset::Open( GDALOpenInfo * poOpenInfo )
free(buff);

/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The GRIB driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
GRIBDataset *poDS;
Expand Down
12 changes: 11 additions & 1 deletion frmts/gsg/gs7bgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,17 @@ GDALDataset *GS7BGDataset::Open( GDALOpenInfo * poOpenInfo )
{
return NULL;
}


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The GS7BG driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
/* ------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* ------------------------------------------------------------------- */
Expand Down
14 changes: 13 additions & 1 deletion frmts/gxf/gxfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,19 @@ GDALDataset *GXFDataset::Open( GDALOpenInfo * poOpenInfo )

if( hGXF == NULL )
return( NULL );


/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
GXFClose(hGXF);
CPLError( CE_Failure, CPLE_NotSupported,
"The GXF driver does not support update access to existing"
" datasets.\n" );
return NULL;
}

/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
Expand Down
27 changes: 21 additions & 6 deletions frmts/hdf4/hdf4dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,12 +1081,27 @@ GDALDataset *HDF4Dataset::Open( GDALOpenInfo * poOpenInfo )
/* -------------------------------------------------------------------- */
if ( CSLCount( poDS->papszSubDatasets ) / 2 == 1 )
{
char *pszSDSName;
pszSDSName = CPLStrdup( CSLFetchNameValue( poDS->papszSubDatasets,
"SUBDATASET_1_NAME" ));
delete poDS;
poDS = (HDF4Dataset *) GDALOpen( pszSDSName, GA_ReadOnly );
CPLFree( pszSDSName );
char *pszSDSName;
pszSDSName = CPLStrdup( CSLFetchNameValue( poDS->papszSubDatasets,
"SUBDATASET_1_NAME" ));
delete poDS;
poDS = (HDF4Dataset *) GDALOpen( pszSDSName, poOpenInfo->eAccess );
CPLFree( pszSDSName );
}
else
{
/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
delete poDS;
CPLError( CE_Failure, CPLE_NotSupported,
"The HDF4 driver does not support update access to existing"
" datasets.\n" );
return NULL;
}

}

return( poDS );
Expand Down
Loading

0 comments on commit a4d23f6

Please sign in to comment.