Skip to content

Commit

Permalink
make QgsVectorLayer::deleteShapefile case-agnostic
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12544 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Dec 20, 2009
1 parent 5f41b5f commit 4bf603b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
11 changes: 3 additions & 8 deletions src/app/legend/qgslegendlayer.cpp
Expand Up @@ -533,7 +533,7 @@ void QgsLegendLayer::saveAsShapefileGeneral( bool saveOnlySelection )
return;

// add the extension if not present
if ( shapefileName.indexOf( ".shp" ) == -1 )
if ( !shapefileName.endsWith( ".shp", Qt::CaseInsensitive ) )
{
shapefileName += ".shp";
}
Expand Down Expand Up @@ -567,13 +567,8 @@ void QgsLegendLayer::saveAsShapefileGeneral( bool saveOnlySelection )

// overwrite the file - user will already have been prompted
// to verify they want to overwrite by the file dialog above
if ( QFile::exists( shapefileName ) )
{
if ( !QgsVectorFileWriter::deleteShapeFile( shapefileName ) )
{
return;
}
}
// might not even exists in the given case.
QgsVectorFileWriter::deleteShapeFile( shapefileName );

// ok if the file existed it should be deleted now so we can continue...
QApplication::setOverrideCursor( Qt::WaitCursor );
Expand Down
27 changes: 13 additions & 14 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -29,6 +29,7 @@
#include <QFile>
#include <QSettings>
#include <QFileInfo>
#include <QDir>
#include <QTextCodec>
#include <QTextStream>
#include <QSet>
Expand Down Expand Up @@ -439,25 +440,23 @@ QgsVectorFileWriter::writeAsShapefile( QgsVectorLayer* layer,

bool QgsVectorFileWriter::deleteShapeFile( QString theFileName )
{
//
// Remove old copies that may be lying around
// TODO: should be case-insensitive
//
QString myFileBase = theFileName.replace( ".shp", "" );
bool ok = true;
QFileInfo fi( theFileName );
QDir dir = fi.dir();

QStringList filter;
const char *suffixes[] = { ".shp", ".shx", ".dbf", ".prj", ".qix", ".qpj" };
for ( std::size_t i = 0; i < sizeof( suffixes ) / sizeof( *suffixes ); i++ )
{
QString file = myFileBase + suffixes[i];
QFileInfo myInfo( file );
if ( myInfo.exists() )
filter << fi.completeBaseName() + suffixes[i];
}

bool ok = true;
foreach( QString file, dir.entryList( filter ) )
{
if ( !QFile::remove( dir.canonicalPath() + "/" + file ) )
{
if ( !QFile::remove( file ) )
{
QgsDebugMsg( "Removing file failed : " + file );
ok = false;
}
QgsDebugMsg( "Removing file failed : " + file );
ok = false;
}
}

Expand Down

0 comments on commit 4bf603b

Please sign in to comment.