Skip to content

Commit 4bf603b

Browse files
author
jef
committed
make QgsVectorLayer::deleteShapefile case-agnostic
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12544 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5f41b5f commit 4bf603b

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

src/app/legend/qgslegendlayer.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ void QgsLegendLayer::saveAsShapefileGeneral( bool saveOnlySelection )
533533
return;
534534

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

568568
// overwrite the file - user will already have been prompted
569569
// to verify they want to overwrite by the file dialog above
570-
if ( QFile::exists( shapefileName ) )
571-
{
572-
if ( !QgsVectorFileWriter::deleteShapeFile( shapefileName ) )
573-
{
574-
return;
575-
}
576-
}
570+
// might not even exists in the given case.
571+
QgsVectorFileWriter::deleteShapeFile( shapefileName );
577572

578573
// ok if the file existed it should be deleted now so we can continue...
579574
QApplication::setOverrideCursor( Qt::WaitCursor );

src/core/qgsvectorfilewriter.cpp

+13-14
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <QFile>
3030
#include <QSettings>
3131
#include <QFileInfo>
32+
#include <QDir>
3233
#include <QTextCodec>
3334
#include <QTextStream>
3435
#include <QSet>
@@ -439,25 +440,23 @@ QgsVectorFileWriter::writeAsShapefile( QgsVectorLayer* layer,
439440

440441
bool QgsVectorFileWriter::deleteShapeFile( QString theFileName )
441442
{
442-
//
443-
// Remove old copies that may be lying around
444-
// TODO: should be case-insensitive
445-
//
446-
QString myFileBase = theFileName.replace( ".shp", "" );
447-
bool ok = true;
443+
QFileInfo fi( theFileName );
444+
QDir dir = fi.dir();
448445

446+
QStringList filter;
449447
const char *suffixes[] = { ".shp", ".shx", ".dbf", ".prj", ".qix", ".qpj" };
450448
for ( std::size_t i = 0; i < sizeof( suffixes ) / sizeof( *suffixes ); i++ )
451449
{
452-
QString file = myFileBase + suffixes[i];
453-
QFileInfo myInfo( file );
454-
if ( myInfo.exists() )
450+
filter << fi.completeBaseName() + suffixes[i];
451+
}
452+
453+
bool ok = true;
454+
foreach( QString file, dir.entryList( filter ) )
455+
{
456+
if ( !QFile::remove( dir.canonicalPath() + "/" + file ) )
455457
{
456-
if ( !QFile::remove( file ) )
457-
{
458-
QgsDebugMsg( "Removing file failed : " + file );
459-
ok = false;
460-
}
458+
QgsDebugMsg( "Removing file failed : " + file );
459+
ok = false;
461460
}
462461
}
463462

0 commit comments

Comments
 (0)