@@ -307,40 +307,21 @@ bool GDALVectorGridAbstractAlgorithm::RunImpl(GDALProgressFunc pfnProgress,
307307
308308 GDALGridOptionsSetProgress (psOptions.get (), pfnProgress, pProgressData);
309309
310- VSIStatBufL sStat ;
311- std::unique_ptr<GDALDataset> poDstDS;
312- const bool fileExists =
313- VSIStatL (m_outputDataset.GetName ().c_str (), &sStat ) == 0 ;
314-
315- {
316- CPLErrorStateBackuper oCPLErrorHandlerPusher (CPLQuietErrorHandler);
317- poDstDS.reset (GDALDataset::Open (m_outputDataset.GetName ().c_str (),
318- GDAL_OF_RASTER | GDAL_OF_UPDATE,
319- nullptr , nullptr , nullptr ));
320- }
321-
322- if (poDstDS)
310+ const char *pszType = " " ;
311+ if (!m_outputDataset.GetName ().empty () &&
312+ GDALDoesFileOrDatasetExist (m_outputDataset.GetName ().c_str (), &pszType))
323313 {
324314 if (!m_overwrite)
325315 {
326- CPLError (CE_Failure, CPLE_AppDefined,
327- " Dataset '%s' already exists. Specify the --overwrite "
328- " option to overwrite it" ,
329- m_outputDataset.GetName ().c_str ());
316+ ReportError (CE_Failure, CPLE_AppDefined,
317+ " %s '%s' already exists. Specify the --overwrite "
318+ " option to overwrite it, or --update to update it. " ,
319+ pszType, m_outputDataset.GetName ().c_str ());
330320 return false ;
331321 }
332- else if (fileExists)
322+ else
333323 {
334- poDstDS.reset ();
335-
336- // Delete the existing file
337- if (VSIUnlink (m_outputDataset.GetName ().c_str ()) != 0 )
338- {
339- CPLError (CE_Failure, CPLE_AppDefined,
340- " Failed to delete existing dataset '%s'." ,
341- m_outputDataset.GetName ().c_str ());
342- return false ;
343- }
324+ VSIUnlink (m_outputDataset.GetName ().c_str ());
344325 }
345326 }
346327
0 commit comments