Commit 89792ded authored by Cédric Traizet's avatar Cédric Traizet

ENH: remove versionproxy::Delete function

parent 8511ebdc
......@@ -64,17 +64,6 @@ namespace version_proxy
* See function documentation for details.
*/
/**
* This function physically deletes an existing dataset.
*
* Calls OGRDataSource::DeleteDataSource for gdal 1.x implementation
* and GDALDriver::Delete for gdal 2.x implementation.
*
* \param name Name of the dataset to destroy.
*/
OTBGdalAdapters_EXPORT
bool Delete(const char * name);
/**
* Return the list of files composing the dataset.
*
......
......@@ -218,8 +218,36 @@ void DeleteDataSource(std::string const& datasourceName)
fileNameHelper->SetExtendedFileName( datasourceName.c_str() );
std::string simpleFileName = fileNameHelper->GetSimpleFileName();
bool ret = otb::ogr::version_proxy::Delete(simpleFileName.c_str());
if (!ret)
// Open dataset
GDALDataset * poDS = (GDALDataset *)GDALOpenEx(
simpleFileName.c_str(),
GDAL_OF_UPDATE | GDAL_OF_VECTOR,
NULL,
NULL,
NULL);
GDALDriver * poDriver = NULL;
bool success =1;
if(poDS)
{
poDriver = poDS->GetDriver();
GDALClose(poDS);
}
else
{
success = false;
}
if(poDriver)
{
OGRErr ret = poDriver->Delete(simpleFileName.c_str());
success = ret == OGRERR_NONE;
}
else
{
success = false;
}
if (!success)
{
itkGenericExceptionMacro(<< "Deletion of data source " << simpleFileName
<< " failed: " << CPLGetLastErrorMsg());
......
......@@ -49,38 +49,6 @@ namespace ogr
namespace version_proxy
{
bool Delete(const char * name)
{
// Open dataset
GDALDataset * poDS = (GDALDataset *)GDALOpenEx(
name,
GDAL_OF_UPDATE | GDAL_OF_VECTOR,
NULL,
NULL,
NULL);
GDALDriver * poDriver = NULL;
if(poDS)
{
poDriver = poDS->GetDriver();
GDALClose(poDS);
}
#if GDAL_VERSION_NUM<2000000
if(poDriver && poDriver->TestCapability(ODrCDeleteDataSource))
{
OGRErr ret = poDriver->DeleteDataSource(name);
return (ret == OGRERR_NONE);
}
#else
if(poDriver)
{
OGRErr ret = poDriver->Delete(name);
return (ret == OGRERR_NONE);
}
#endif
return false;
}
#if GDAL_VERSION_NUM>=2000000
namespace raii
{
......
......@@ -238,7 +238,23 @@ void OGRVectorDataIO::Write(const itk::DataObject* datag, char ** /** unused */)
}
// Erase the dataSource if already exist
ogr::version_proxy::Delete(this->m_FileName.c_str());
GDALDataset * poDS = (GDALDataset *)GDALOpenEx(
this->m_FileName.c_str(),
GDAL_OF_UPDATE | GDAL_OF_VECTOR,
NULL,
NULL,
NULL);
GDALDriver * poDriver = NULL;
if(poDS)
{
poDriver = poDS->GetDriver();
GDALClose(poDS);
}
if(poDriver)
{
poDriver->Delete(this->m_FileName.c_str());
}
m_DataSource = ogrDriver->Create( this->m_FileName.c_str(),
0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment