Skip to content

Commit

Permalink
PAM: preserve existing metadata when setting new one (fixes #1430)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Apr 9, 2019
1 parent 5b9501f commit b711807
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions autotest/gcore/pam.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,25 @@ def test_pam_13():

gdal.SetConfigOption('GDAL_PAM_ENABLED', 'YES')

###############################################################################
# Test that existing PAM metadata is preserved when new is added
# https://github.com/OSGeo/gdal/issues/1430


def test_pam_metadata_preserved():

tmpfilename = '/vsimem/tmp.pnm'
ds = gdal.GetDriverByName('PNM').Create(tmpfilename, 1, 1)
ds.SetMetadataItem('foo', 'bar')
ds = None
ds = gdal.Open(tmpfilename)
ds.GetRasterBand(1).SetMetadataItem('bar', 'baz')
ds = None
ds = gdal.Open(tmpfilename)
assert ds.GetMetadataItem('foo') == 'bar'
assert ds.GetRasterBand(1).GetMetadataItem('bar') == 'baz'
ds = None
gdal.GetDriverByName('PNM').Delete(tmpfilename)

###############################################################################
# Cleanup.
Expand Down
5 changes: 4 additions & 1 deletion gdal/gcore/gdalpamdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ CPLErr GDALPamDataset::XMLInit( CPLXMLNode *psTree, const char *pszUnused )
/* -------------------------------------------------------------------- */
/* Apply any dataset level metadata. */
/* -------------------------------------------------------------------- */
oMDMD.XMLInit( psTree, TRUE );
if( oMDMD.XMLInit( psTree, TRUE ) )
{
psPam->bHasMetadata = TRUE;
}

/* -------------------------------------------------------------------- */
/* Try loading ESRI xml encoded GeodataXform. */
Expand Down

0 comments on commit b711807

Please sign in to comment.