Skip to content

Commit f4dfc9a

Browse files
committed
Implement GDALPamDataset::Close()
1 parent 14392f6 commit f4dfc9a

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

gcore/gdal_pam.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class CPL_DLL GDALPamDataset : public GDALDataset
137137
public:
138138
~GDALPamDataset() override;
139139

140+
CPLErr Close() override;
141+
140142
CPLErr FlushCache(bool bAtClosing) override;
141143

142144
const OGRSpatialReference *GetSpatialRef() const override;

gcore/gdalpamdataset.cpp

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,37 @@ GDALPamDataset::GDALPamDataset()
148148
GDALPamDataset::~GDALPamDataset()
149149

150150
{
151-
if (IsMarkedSuppressOnClose())
152-
{
153-
if (psPam && psPam->pszPamFilename != nullptr)
154-
VSIUnlink(psPam->pszPamFilename);
155-
}
156-
else if (nPamFlags & GPF_DIRTY)
157-
{
158-
CPLDebug("GDALPamDataset", "In destructor with dirty metadata.");
159-
GDALPamDataset::TrySaveXML();
160-
}
151+
GDALPamDataset::Close();
161152

162153
PamClear();
163154
}
164155

156+
/************************************************************************/
157+
/* Close() */
158+
/************************************************************************/
159+
160+
CPLErr GDALPamDataset::Close()
161+
{
162+
CPLErr eErr = CE_None;
163+
if (nOpenFlags != OPEN_FLAGS_CLOSED)
164+
{
165+
if (IsMarkedSuppressOnClose())
166+
{
167+
if (psPam && psPam->pszPamFilename != nullptr)
168+
VSIUnlink(psPam->pszPamFilename);
169+
}
170+
else if (nPamFlags & GPF_DIRTY)
171+
{
172+
CPLDebug("GDALPamDataset", "In Close() with dirty metadata.");
173+
eErr = GDALPamDataset::TrySaveXML();
174+
}
175+
176+
if (GDALDataset::Close() != CE_None)
177+
eErr = CE_Failure;
178+
}
179+
return eErr;
180+
}
181+
165182
/************************************************************************/
166183
/* FlushCache() */
167184
/************************************************************************/

0 commit comments

Comments
 (0)