Skip to content

Commit

Permalink
VRT driver : properly set eAccess flag to avoid erros on vrtrawlink.p…
Browse files Browse the repository at this point in the history
…y, particularly when GDAL_FORCE_CACHING=YES is set (#3133)

git-svn-id: https://svn.osgeo.org/gdal/trunk/gdal@17624 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
rouault committed Sep 8, 2009
1 parent 34ab190 commit 896ea7d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
10 changes: 10 additions & 0 deletions frmts/raw/rawdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ RawRasterBand::~RawRasterBand()
CPLFree( pLineBuffer );
}


/************************************************************************/
/* SetAccess() */
/************************************************************************/

void RawRasterBand::SetAccess( GDALAccess eAccess )
{
this->eAccess = eAccess;
}

/************************************************************************/
/* FlushCache() */
/* */
Expand Down
2 changes: 2 additions & 0 deletions frmts/raw/rawdataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class CPL_DLL RawRasterBand : public GDALPamRasterBand

CPLErr AccessLine( int iLine );

void SetAccess( GDALAccess eAccess );

// this is deprecated.
void StoreNoDataValue( double );

Expand Down
11 changes: 8 additions & 3 deletions frmts/vrt/vrtdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ GDALDataset *VRTDataset::Open( GDALOpenInfo * poOpenInfo )
/* -------------------------------------------------------------------- */
/* Turn the XML representation into a VRTDataset. */
/* -------------------------------------------------------------------- */
VRTDataset *poDS = (VRTDataset *) OpenXML( pszXML, pszVRTPath );
VRTDataset *poDS = (VRTDataset *) OpenXML( pszXML, pszVRTPath, poOpenInfo->eAccess );

if( poDS != NULL )
poDS->bNeedsFlush = FALSE;
Expand All @@ -699,7 +699,8 @@ GDALDataset *VRTDataset::Open( GDALOpenInfo * poOpenInfo )
/* of the dataset. */
/************************************************************************/

GDALDataset *VRTDataset::OpenXML( const char *pszXML, const char *pszVRTPath )
GDALDataset *VRTDataset::OpenXML( const char *pszXML, const char *pszVRTPath,
GDALAccess eAccess)

{
/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -733,7 +734,10 @@ GDALDataset *VRTDataset::OpenXML( const char *pszXML, const char *pszVRTPath )
if( strstr(pszXML,"VRTWarpedDataset") != NULL )
poDS = new VRTWarpedDataset( nXSize, nYSize );
else
{
poDS = new VRTDataset( nXSize, nYSize );
poDS->eAccess = eAccess;
}

if( poDS->XMLInit( psTree, pszVRTPath ) != CE_None )
{
Expand Down Expand Up @@ -913,7 +917,7 @@ VRTDataset::Create( const char * pszName,

if( EQUALN(pszName,"<VRTDataset",11) )
{
GDALDataset *poDS = OpenXML( pszName, NULL );
GDALDataset *poDS = OpenXML( pszName, NULL, GA_Update );
poDS->SetDescription( "<FromXML>" );
return poDS;
}
Expand All @@ -935,6 +939,7 @@ VRTDataset::Create( const char * pszName,
pszSubclass );
return NULL;
}
poDS->eAccess = GA_Update;

poDS->SetDescription( pszName );

Expand Down
2 changes: 1 addition & 1 deletion frmts/vrt/vrtdataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class CPL_DLL VRTDataset : public GDALDataset

static int Identify( GDALOpenInfo * );
static GDALDataset *Open( GDALOpenInfo * );
static GDALDataset *OpenXML( const char *, const char * = NULL );
static GDALDataset *OpenXML( const char *, const char * = NULL, GDALAccess eAccess = GA_ReadOnly );
static GDALDataset *Create( const char * pszName,
int nXSize, int nYSize, int nBands,
GDALDataType eType, char ** papszOptions );
Expand Down
16 changes: 14 additions & 2 deletions frmts/vrt/vrtrawrasterband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ CPLErr VRTRawRasterBand::IRasterIO( GDALRWFlag eRWFlag,
return CE_Failure;
}

if( eRWFlag == GF_Write && eAccess == GA_ReadOnly )
{
CPLError( CE_Failure, CPLE_NoWriteAccess,
"Attempt to write to read only dataset in"
"VRTRawRasterBand::IRasterIO().\n" );

return( CE_Failure );
}

/* -------------------------------------------------------------------- */
/* Do we have overviews that would be appropriate to satisfy */
/* this request? */
Expand All @@ -101,6 +110,8 @@ CPLErr VRTRawRasterBand::IRasterIO( GDALRWFlag eRWFlag,
eBufType, nPixelSpace, nLineSpace ) == CE_None )
return CE_None;
}

poRawRaster->SetAccess(eAccess);

return poRawRaster->RasterIO( eRWFlag, nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize,
Expand Down Expand Up @@ -139,7 +150,9 @@ CPLErr VRTRawRasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff,
"No raw raster band configured on VRTRawRasterBand." );
return CE_Failure;
}


poRawRaster->SetAccess(eAccess);

return poRawRaster->WriteBlock( nBlockXOff, nBlockYOff, pImage );
}

Expand Down Expand Up @@ -238,7 +251,6 @@ CPLErr VRTRawRasterBand::SetRawLink( const char *pszFilename,
return CE_None;
}


/************************************************************************/
/* ClearRawLink() */
/************************************************************************/
Expand Down

0 comments on commit 896ea7d

Please sign in to comment.