@@ -293,20 +293,7 @@ GDALDataset::~GDALDataset()
293293 CPLDebug (" GDAL" , " GDALClose(%s, this=%p)" , GetDescription (), this );
294294 }
295295
296- if (IsMarkedSuppressOnClose ())
297- {
298- if (poDriver == nullptr ||
299- // Someone issuing Create("foo.tif") on a
300- // memory driver doesn't expect files with those names to be deleted
301- // on a file system...
302- // This is somewhat messy. Ideally there should be a way for the
303- // driver to overload the default behavior
304- (!EQUAL (poDriver->GetDescription (), " MEM" ) &&
305- !EQUAL (poDriver->GetDescription (), " Memory" )))
306- {
307- VSIUnlink (GetDescription ());
308- }
309- }
296+ GDALDataset::Close ();
310297
311298 /* -------------------------------------------------------------------- */
312299 /* Remove dataset from the "open" dataset list. */
@@ -461,10 +448,30 @@ GDALDataset::~GDALDataset()
461448 */
462449CPLErr GDALDataset::Close ()
463450{
464- // Call UnregisterFromSharedDataset() before altering nOpenFlags
465- UnregisterFromSharedDataset ();
451+ if (nOpenFlags != OPEN_FLAGS_CLOSED)
452+ {
453+ // Call UnregisterFromSharedDataset() before altering nOpenFlags
454+ UnregisterFromSharedDataset ();
455+
456+ nOpenFlags = OPEN_FLAGS_CLOSED;
457+ }
458+
459+ if (IsMarkedSuppressOnClose ())
460+ {
461+ if (poDriver == nullptr ||
462+ // Someone issuing Create("foo.tif") on a
463+ // memory driver doesn't expect files with those names to be deleted
464+ // on a file system...
465+ // This is somewhat messy. Ideally there should be a way for the
466+ // driver to overload the default behavior
467+ (!EQUAL (poDriver->GetDescription (), " MEM" ) &&
468+ !EQUAL (poDriver->GetDescription (), " Memory" )))
469+ {
470+ if (VSIUnlink (GetDescription ()) == 0 )
471+ UnMarkSuppressOnClose ();
472+ }
473+ }
466474
467- nOpenFlags = OPEN_FLAGS_CLOSED;
468475 return CE_None;
469476}
470477
0 commit comments