Skip to content

Commit 06d2d79

Browse files
committedSep 14, 2016
Make sure files are truncated before writing
1 parent b4d9f64 commit 06d2d79

37 files changed

+49
-49
lines changed
 

‎src/analysis/interpolation/qgsgridfilewriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int QgsGridFileWriter::writeFile( bool showProgressDialog )
4848
{
4949
QFile outputFile( mOutputFilePath );
5050

51-
if ( !outputFile.open( QFile::WriteOnly ) )
51+
if ( !outputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
5252
{
5353
return 1;
5454
}
@@ -111,7 +111,7 @@ int QgsGridFileWriter::writeFile( bool showProgressDialog )
111111
QFileInfo fi( mOutputFilePath );
112112
QString fileName = fi.absolutePath() + '/' + fi.completeBaseName() + ".prj";
113113
QFile prjFile( fileName );
114-
if ( !prjFile.open( QFile::WriteOnly ) )
114+
if ( !prjFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
115115
{
116116
return 1;
117117
}

‎src/analysis/raster/qgsrelief.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ bool QgsRelief::exportFrequencyDistributionToCsv( const QString& file )
574574

575575
//write out frequency values to csv file for debugging
576576
QFile outFile( file );
577-
if ( !outFile.open( QIODevice::WriteOnly ) )
577+
if ( !outFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
578578
{
579579
return false;
580580
}

‎src/app/composer/qgscomposer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,7 +2877,7 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
28772877
QFileInfo fi( outputFileName );
28782878
QString currentFileName = i == 0 ? outputFileName : fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix();
28792879
QFile out( currentFileName );
2880-
bool openOk = out.open( QIODevice::WriteOnly | QIODevice::Text );
2880+
bool openOk = out.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate );
28812881
if ( !openOk )
28822882
{
28832883
QMessageBox::warning( this, tr( "SVG export error" ),
@@ -3099,7 +3099,7 @@ void QgsComposer::on_mActionSaveAsTemplate_triggered()
30993099
settings.setValue( "UI/lastComposerTemplateDir", saveFileInfo.absolutePath() );
31003100

31013101
QFile templateFile( saveFileName );
3102-
if ( !templateFile.open( QIODevice::WriteOnly ) )
3102+
if ( !templateFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
31033103
{
31043104
return;
31053105
}
@@ -4068,7 +4068,7 @@ void QgsComposer::createComposerView()
40684068
void QgsComposer::writeWorldFile( const QString& worldFileName, double a, double b, double c, double d, double e, double f ) const
40694069
{
40704070
QFile worldFile( worldFileName );
4071-
if ( !worldFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
4071+
if ( !worldFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
40724072
{
40734073
return;
40744074
}

‎src/app/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ int main( int argc, char *argv[] )
12291229
QFile dxfFile;
12301230
if ( dxfOutputFile == "-" )
12311231
{
1232-
if ( !dxfFile.open( stdout, QIODevice::WriteOnly ) )
1232+
if ( !dxfFile.open( stdout, QIODevice::WriteOnly | QIODevice::Truncate ) )
12331233
{
12341234
std::cerr << "could not open stdout" << std::endl;
12351235
return 2;

‎src/app/qgsbookmarks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ void QgsBookmarks::exportToXml()
372372
}
373373

374374
QFile f( fileName );
375-
if ( !f.open( QFile::WriteOnly ) )
375+
if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
376376
{
377377
f.close();
378378
return;

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ void QgsRasterLayerProperties::on_pbnExportTransparentPixelValues_clicked()
12811281
}
12821282

12831283
QFile myOutputFile( myFileName );
1284-
if ( myOutputFile.open( QFile::WriteOnly ) )
1284+
if ( myOutputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
12851285
{
12861286
QTextStream myOutputStream( &myOutputFile );
12871287
myOutputStream << "# " << tr( "QGIS Generated Transparent Pixel Value Export File" ) << '\n';

‎src/app/qgssubstitutionlistwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void QgsSubstitutionListWidget::on_mButtonExport_clicked()
107107
doc.appendChild( root );
108108

109109
QFile file( fileName );
110-
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
110+
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
111111
{
112112
QMessageBox::warning( nullptr, tr( "Export substitutions" ),
113113
tr( "Cannot write file %1:\n%2." ).arg( fileName, file.errorString() ),

‎src/core/auth/qgsauthcertutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ QString QgsAuthCertUtils::pemTextToTempFile( const QString &name, const QByteArr
253253
QFile pemFile( QDir::tempPath() + QDir::separator() + name );
254254
QString pemFilePath( pemFile.fileName() );
255255

256-
if ( pemFile.open( QIODevice::WriteOnly ) )
256+
if ( pemFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
257257
{
258258
qint64 bytesWritten = pemFile.write( pemtext );
259259
if ( bytesWritten == -1 )

‎src/core/qgsapplication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ void QgsApplication::setUITheme( const QString &themeName )
494494

495495
if ( variableInfo.exists() && variablesfile.open( QIODevice::ReadOnly ) )
496496
{
497-
if ( !file.open( QIODevice::ReadOnly ) || !fileout.open( QIODevice::WriteOnly | QIODevice::Text ) )
497+
if ( !file.open( QIODevice::ReadOnly ) || !fileout.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
498498
{
499499
return;
500500
}

‎src/core/qgsrenderchecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ bool QgsRenderChecker::runTest( const QString& theTestName,
230230
//create a world file to go with the image...
231231

232232
QFile wldFile( QDir::tempPath() + '/' + theTestName + "_result.wld" );
233-
if ( wldFile.open( QIODevice::WriteOnly ) )
233+
if ( wldFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
234234
{
235235
QgsRectangle r = mMapSettings.extent();
236236

‎src/core/qgsscaleutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool QgsScaleUtils::saveScaleList( const QString &fileName, const QStringList &s
3434
}
3535

3636
QFile file( fileName );
37-
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
37+
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
3838
{
3939
errorMessage = QString( "Cannot write file %1:\n%2." ).arg( fileName, file.errorString() );
4040
return false;

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
363363
{
364364
QString layerName = vectorFileName.left( vectorFileName.indexOf( ".shp", Qt::CaseInsensitive ) );
365365
QFile prjFile( layerName + ".qpj" );
366-
if ( prjFile.open( QIODevice::WriteOnly ) )
366+
if ( prjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
367367
{
368368
QTextStream prjStream( &prjFile );
369369
prjStream << srs.toWkt().toLocal8Bit().constData() << endl;

‎src/core/symbology-ng/qgsstyle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ bool QgsStyle::exportXml( const QString& filename )
13881388

13891389
// save
13901390
QFile f( filename );
1391-
if ( !f.open( QFile::WriteOnly ) )
1391+
if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
13921392
{
13931393
mErrorString = "Couldn't open file for writing: " + filename;
13941394
return false;

‎src/core/symbology-ng/qgssymbollayerutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2950,7 +2950,7 @@ QMimeData* QgsSymbolLayerUtils::colorListToMimeData( const QgsNamedColorList& co
29502950

29512951
bool QgsSymbolLayerUtils::saveColorsToGpl( QFile &file, const QString& paletteName, const QgsNamedColorList& colors )
29522952
{
2953-
if ( !file.open( QIODevice::ReadWrite ) )
2953+
if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
29542954
{
29552955
return false;
29562956
}

‎src/gui/qgsconfigureshortcutsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void QgsConfigureShortcutsDialog::saveShortcuts()
139139
}
140140

141141
QFile file( fileName );
142-
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
142+
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
143143
{
144144
QMessageBox::warning( this, tr( "Saving shortcuts" ),
145145
tr( "Cannot write file %1:\n%2." )

‎src/gui/qgsmanageconnectionsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void QgsManageConnectionsDialog::doExportImport()
133133
}
134134

135135
QFile file( mFileName );
136-
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
136+
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
137137
{
138138
QMessageBox::warning( this, tr( "Saving connections" ),
139139
tr( "Cannot write file %1:\n%2." )

‎src/gui/qgsmapcanvas.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ void QgsMapCanvas::saveAsImage( const QString& theFileName, QPixmap * theQPixmap
782782
QString myWorldFileName = myInfo.absolutePath() + '/' + myInfo.baseName() + '.'
783783
+ outputSuffix.at( 0 ) + outputSuffix.at( myInfo.suffix().size() - 1 ) + 'w';
784784
QFile myWorldFile( myWorldFileName );
785-
if ( !myWorldFile.open( QIODevice::WriteOnly ) ) //don't use QIODevice::Text
785+
if ( !myWorldFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) //don't use QIODevice::Text
786786
{
787787
return;
788788
}

‎src/gui/qgssearchquerybuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void QgsSearchQueryBuilder::saveQuery()
379379
}
380380

381381
QFile saveFile( saveFileName );
382-
if ( !saveFile.open( QIODevice::WriteOnly ) )
382+
if ( !saveFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
383383
{
384384
QMessageBox::critical( nullptr, tr( "Error" ), tr( "Could not open file for writing" ) );
385385
return;

‎src/gui/raster/qgsrastertransparencywidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void QgsRasterTransparencyWidget::on_pbnExportTransparentPixelValues_clicked()
251251
}
252252

253253
QFile myOutputFile( myFileName );
254-
if ( myOutputFile.open( QFile::WriteOnly ) )
254+
if ( myOutputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
255255
{
256256
QTextStream myOutputStream( &myOutputFile );
257257
myOutputStream << "# " << tr( "QGIS Generated Transparent Pixel Value Export File" ) << '\n';

‎src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
670670
}
671671

672672
QFile outputFile( fileName );
673-
if ( outputFile.open( QFile::WriteOnly ) )
673+
if ( outputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
674674
{
675675
QTextStream outputStream( &outputFile );
676676
outputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << '\n';

‎src/plugins/georeferencer/qgsgeorefplugingui.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ bool QgsGeorefPluginGui::loadGCPs( /*bool verbose*/ )
12801280
void QgsGeorefPluginGui::saveGCPs()
12811281
{
12821282
QFile pointFile( mGCPpointsFileName );
1283-
if ( pointFile.open( QIODevice::WriteOnly ) )
1283+
if ( pointFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
12841284
{
12851285
QTextStream points( &pointFile );
12861286
points << "mapX,mapY,pixelX,pixelY,enable" << endl;
@@ -1422,7 +1422,7 @@ bool QgsGeorefPluginGui::writeWorldFile( const QgsPoint& origin, double pixelXSi
14221422
{
14231423
// write the world file
14241424
QFile file( mWorldFileName );
1425-
if ( !file.open( QIODevice::WriteOnly ) )
1425+
if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
14261426
{
14271427
mMessageBar->pushMessage( tr( "Error" ), tr( "Could not write to %1." ).arg( mWorldFileName ), QgsMessageBar::CRITICAL, messageTimeout() );
14281428
return false;

‎src/plugins/grass/qgsgrassmapcalc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ void QgsGrassMapcalc::save()
10521052
+ "/mapcalc/" + mFileName;
10531053

10541054
QFile out( path );
1055-
if ( !out.open( QIODevice::WriteOnly ) )
1055+
if ( !out.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
10561056
{
10571057
QMessageBox::warning( this, tr( "Save mapcalc" ),
10581058
tr( "Cannot open mapcalc file" ) );

‎src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void QgsRasterTerrainAnalysisDialog::on_mExportColorsButton_clicked()
249249
}
250250

251251
QFile outputFile( file );
252-
if ( !outputFile.open( QIODevice::WriteOnly ) )
252+
if ( !outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
253253
{
254254
return;
255255
}

‎src/providers/gpx/qgsgpxprovider.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ bool QgsGPXProvider::addFeatures( QgsFeatureList & flist )
203203

204204
// write back to file
205205
QFile file( mFileName );
206-
if ( !file.open( QIODevice::WriteOnly ) )
206+
if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
207207
return false;
208208
QTextStream ostr( &file );
209209
data->writeXml( ostr );
@@ -391,7 +391,7 @@ bool QgsGPXProvider::deleteFeatures( const QgsFeatureIds & id )
391391

392392
// write back to file
393393
QFile file( mFileName );
394-
if ( !file.open( QIODevice::WriteOnly ) )
394+
if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
395395
return false;
396396
QTextStream ostr( &file );
397397
data->writeXml( ostr );
@@ -441,7 +441,7 @@ bool QgsGPXProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
441441

442442
// write back to file
443443
QFile file( mFileName );
444-
if ( !file.open( QIODevice::WriteOnly ) )
444+
if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
445445
return false;
446446
QTextStream ostr( &file );
447447
data->writeXml( ostr );

‎src/providers/ogr/qgsogrdataitems.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
7474
char* pszOutWkt = nullptr;
7575
OSRExportToWkt( hSRS, &pszOutWkt );
7676
QFile prjFile( layerName + ".prj" );
77-
if ( prjFile.open( QIODevice::WriteOnly ) )
77+
if ( prjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
7878
{
7979
QTextStream prjStream( &prjFile );
8080
prjStream << pszOutWkt << endl;
@@ -90,7 +90,7 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
9090

9191
// save qgis-specific .qpj file (maybe because of better wkt compatibility?)
9292
QFile qpjFile( layerName + ".qpj" );
93-
if ( qpjFile.open( QIODevice::WriteOnly ) )
93+
if ( qpjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
9494
{
9595
QTextStream qpjStream( &qpjFile );
9696
qpjStream << wkt.toLocal8Bit().data() << endl;

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
26632663
{
26642664
QString layerName = uri.left( uri.indexOf( ".shp", Qt::CaseInsensitive ) );
26652665
QFile prjFile( layerName + ".qpj" );
2666-
if ( prjFile.open( QIODevice::WriteOnly ) )
2666+
if ( prjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
26672667
{
26682668
QTextStream prjStream( &prjFile );
26692669
prjStream << myWkt.toLocal8Bit().data() << endl;

‎src/providers/wcs/qgswcscapabilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ bool QgsWcsCapabilities::parseCapabilitiesDom( QByteArray const &xml, QgsWcsCapa
427427
QgsDebugMsg( "Entered." );
428428
#ifdef QGISDEBUG
429429
QFile file( QDir::tempPath() + "/qgis-wcs-capabilities.xml" );
430-
if ( file.open( QIODevice::WriteOnly ) )
430+
if ( file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
431431
{
432432
file.write( xml );
433433
file.close();

‎src/providers/wfs/qgswfsfeatureiterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ void QgsWFSFeatureIterator::featureReceivedSynchronous( QVector<QgsWFSFeatureGml
904904
mWriterFilename = QDir( QgsWFSUtils::acquireCacheDirectory() ).filePath( QString( "iterator_%1_%2.bin" ).arg( thisStr ).arg( mCounter ) );
905905
QgsDebugMsg( QString( "Transferring feature iterator cache to %1" ).arg( mWriterFilename ) );
906906
mWriterFile = new QFile( mWriterFilename );
907-
if ( !mWriterFile->open( QIODevice::WriteOnly ) )
907+
if ( !mWriterFile->open( QIODevice::WriteOnly | QIODevice::Truncate ) )
908908
{
909909
QgsDebugMsg( QString( "Cannot open %1 for writing" ).arg( mWriterFilename ) );
910910
delete mWriterFile;

‎src/providers/wfs/qgswfsshareddata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ bool QgsWFSSharedData::createCache()
354354

355355
// Copy the in-memory template Spatialite DB into the target DB
356356
QFile dbFile( mCacheDbname );
357-
if ( !dbFile.open( QIODevice::WriteOnly ) )
357+
if ( !dbFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
358358
{
359359
QgsMessageLog::logMessage( tr( "Cannot create temporary SpatiaLite cache" ), tr( "WFS" ) );
360360
return false;

‎src/providers/wms/qgswmscapabilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ bool QgsWmsCapabilities::parseCapabilitiesDom( QByteArray const &xml, QgsWmsCapa
249249

250250
#ifdef QGISDEBUG
251251
QFile file( QDir::tempPath() + "/qgis-wmsprovider-capabilities.xml" );
252-
if ( file.open( QIODevice::WriteOnly ) )
252+
if ( file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
253253
{
254254
file.write( xml );
255255
file.close();

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3835,7 +3835,7 @@ void QgsWmsTiledImageDownloadHandler::tileReplyFinished()
38353835
.arg( reply->url().toString() ), tr( "WMS" ) );
38363836
#ifdef QGISDEBUG
38373837
QFile file( QDir::tempPath() + "/broken-image.png" );
3838-
if ( file.open( QIODevice::WriteOnly ) )
3838+
if ( file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
38393839
{
38403840
file.write( text );
38413841
file.close();

‎src/server/qgsmsutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ QString QgsMSUtils::createTempFilePath()
7070
int QgsMSUtils::createTextFile( const QString& filePath, const QString& text )
7171
{
7272
QFile file( filePath );
73-
if ( file.open( QIODevice::WriteOnly | QIODevice::Text ) )
73+
if ( file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
7474
{
7575
QTextStream fileStream( &file );
7676
fileStream << text;

‎src/server/qgssoaprequesthandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ int QgsSOAPRequestHandler::setUrlToFile( QImage* img )
768768
theFile.setFileName( tmpMasDir.absolutePath() + "/" + folderName + "/map.png" );
769769
uri.append( "/mas_tmp/" + folderName + "/map.png" );
770770
}
771-
if ( !theFile.open( QIODevice::WriteOnly ) )
771+
if ( !theFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
772772
{
773773
QgsDebugMsg( "Error, could not open file" );
774774
return 4;

‎tests/bench/qgsbench.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ QString QgsBench::serialize( const QMap<QString, QVariant>& theMap, int level )
335335
void QgsBench::saveLog( const QString & fileName )
336336
{
337337
QFile file( fileName );
338-
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
338+
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
339339
return;
340340

341341
QTextStream out( &file );

‎tests/src/core/testqgis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void TestQgis::cleanupTestCase()
5757
{
5858
QString myReportFile = QDir::tempPath() + "/qgistest.html";
5959
QFile myFile( myReportFile );
60-
if ( myFile.open( QIODevice::WriteOnly ) )
60+
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
6161
{
6262
QTextStream myQTextStream( &myFile );
6363
myQTextStream << mReport;

‎tests/src/core/testqgsauthmanager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void TestQgsAuthManager::initTestCase()
105105
// create QGIS_AUTH_PASSWORD_FILE file
106106
QString passfilepath = mTempDir + "/passfile";
107107
QFile passfile( passfilepath );
108-
if ( passfile.open( QIODevice::WriteOnly | QIODevice::Text ) )
108+
if ( passfile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
109109
{
110110
QTextStream fout( &passfile );
111111
fout << QString( mPass ) << "\r\n";
@@ -149,7 +149,7 @@ void TestQgsAuthManager::cleanupTestCase()
149149

150150
QString myReportFile = QDir::tempPath() + "/qgistest.html";
151151
QFile myFile( myReportFile );
152-
if ( myFile.open( QIODevice::WriteOnly ) )
152+
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
153153
{
154154
QTextStream myQTextStream( &myFile );
155155
myQTextStream << mReport;

‎tests/src/providers/testqgswcspublicservers.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void TestQgsWcsPublicServers::test()
422422
{
423423
uri = myPath + "-gdal.xml";
424424
QFile myGdalXmlFile( uri );
425-
Q_ASSERT( myGdalXmlFile.open( QIODevice::WriteOnly | QIODevice::Text ) );
425+
Q_ASSERT( myGdalXmlFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) );
426426
QTextStream myStream( &myGdalXmlFile );
427427
myStream << "<WCS_GDAL>\n";
428428
myStream << " <ServiceURL>" + serverUrl + '?' + "</ServiceURL>\n";
@@ -519,7 +519,7 @@ void TestQgsWcsPublicServers::test()
519519

520520
QFile myLogFile( myLogPath );
521521

522-
Q_ASSERT( myLogFile.open( QIODevice::WriteOnly | QIODevice::Text ) );
522+
Q_ASSERT( myLogFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) );
523523
QTextStream myStream( &myLogFile );
524524
myStream << myLog.join( "\n" );
525525

@@ -531,13 +531,13 @@ void TestQgsWcsPublicServers::test()
531531
QgsDebugMsg( "Coverage not found" );
532532
}
533533
QFile myVersionLogFile( myVersionLogPath );
534-
Q_ASSERT( myVersionLogFile.open( QIODevice::WriteOnly | QIODevice::Text ) );
534+
Q_ASSERT( myVersionLogFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) );
535535
QTextStream myVersionStream( &myVersionLogFile );
536536
myVersionStream << myVersionLog.join( "\n" );
537537
myVersionLogFile.close();
538538
}
539539
QFile myServerLogFile( myServerLogPath );
540-
Q_ASSERT( myServerLogFile.open( QIODevice::WriteOnly | QIODevice::Text ) );
540+
Q_ASSERT( myServerLogFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) );
541541
QTextStream myServerStream( &myServerLogFile );
542542
myServerStream << myServerLog.join( "\n" );
543543
myServerLogFile.close();
@@ -548,7 +548,7 @@ void TestQgsWcsPublicServers::writeReport( const QString& theReport )
548548
{
549549
QString myReportFile = mCacheDir.absolutePath() + "/index.html";
550550
QFile myFile( myReportFile );
551-
if ( myFile.open( QIODevice::WriteOnly ) )
551+
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
552552
{
553553
QTextStream myStream( &myFile );
554554
myStream << theReport;

0 commit comments

Comments
 (0)
Please sign in to comment.