Skip to content
Permalink
Browse files

Make sure files are truncated before writing

  • Loading branch information
nyalldawson committed Sep 14, 2016
1 parent b4d9f64 commit 06d2d79185367d951dceafbfd3343b6a4d1e7293
Showing with 49 additions and 49 deletions.
  1. +2 −2 src/analysis/interpolation/qgsgridfilewriter.cpp
  2. +1 −1 src/analysis/raster/qgsrelief.cpp
  3. +3 −3 src/app/composer/qgscomposer.cpp
  4. +1 −1 src/app/main.cpp
  5. +1 −1 src/app/qgsbookmarks.cpp
  6. +1 −1 src/app/qgsrasterlayerproperties.cpp
  7. +1 −1 src/app/qgssubstitutionlistwidget.cpp
  8. +1 −1 src/core/auth/qgsauthcertutils.cpp
  9. +1 −1 src/core/qgsapplication.cpp
  10. +1 −1 src/core/qgsrenderchecker.cpp
  11. +1 −1 src/core/qgsscaleutils.cpp
  12. +1 −1 src/core/qgsvectorfilewriter.cpp
  13. +1 −1 src/core/symbology-ng/qgsstyle.cpp
  14. +1 −1 src/core/symbology-ng/qgssymbollayerutils.cpp
  15. +1 −1 src/gui/qgsconfigureshortcutsdialog.cpp
  16. +1 −1 src/gui/qgsmanageconnectionsdialog.cpp
  17. +1 −1 src/gui/qgsmapcanvas.cpp
  18. +1 −1 src/gui/qgssearchquerybuilder.cpp
  19. +1 −1 src/gui/raster/qgsrastertransparencywidget.cpp
  20. +1 −1 src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
  21. +2 −2 src/plugins/georeferencer/qgsgeorefplugingui.cpp
  22. +1 −1 src/plugins/grass/qgsgrassmapcalc.cpp
  23. +1 −1 src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp
  24. +3 −3 src/providers/gpx/qgsgpxprovider.cpp
  25. +2 −2 src/providers/ogr/qgsogrdataitems.cpp
  26. +1 −1 src/providers/ogr/qgsogrprovider.cpp
  27. +1 −1 src/providers/wcs/qgswcscapabilities.cpp
  28. +1 −1 src/providers/wfs/qgswfsfeatureiterator.cpp
  29. +1 −1 src/providers/wfs/qgswfsshareddata.cpp
  30. +1 −1 src/providers/wms/qgswmscapabilities.cpp
  31. +1 −1 src/providers/wms/qgswmsprovider.cpp
  32. +1 −1 src/server/qgsmsutils.cpp
  33. +1 −1 src/server/qgssoaprequesthandler.cpp
  34. +1 −1 tests/bench/qgsbench.cpp
  35. +1 −1 tests/src/core/testqgis.cpp
  36. +2 −2 tests/src/core/testqgsauthmanager.cpp
  37. +5 −5 tests/src/providers/testqgswcspublicservers.cpp
@@ -48,7 +48,7 @@ int QgsGridFileWriter::writeFile( bool showProgressDialog )
{
QFile outputFile( mOutputFilePath );

if ( !outputFile.open( QFile::WriteOnly ) )
if ( !outputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
{
return 1;
}
@@ -111,7 +111,7 @@ int QgsGridFileWriter::writeFile( bool showProgressDialog )
QFileInfo fi( mOutputFilePath );
QString fileName = fi.absolutePath() + '/' + fi.completeBaseName() + ".prj";
QFile prjFile( fileName );
if ( !prjFile.open( QFile::WriteOnly ) )
if ( !prjFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
{
return 1;
}
@@ -574,7 +574,7 @@ bool QgsRelief::exportFrequencyDistributionToCsv( const QString& file )

//write out frequency values to csv file for debugging
QFile outFile( file );
if ( !outFile.open( QIODevice::WriteOnly ) )
if ( !outFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
return false;
}
@@ -2877,7 +2877,7 @@ void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
QFileInfo fi( outputFileName );
QString currentFileName = i == 0 ? outputFileName : fi.absolutePath() + '/' + fi.baseName() + '_' + QString::number( i + 1 ) + '.' + fi.suffix();
QFile out( currentFileName );
bool openOk = out.open( QIODevice::WriteOnly | QIODevice::Text );
bool openOk = out.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate );
if ( !openOk )
{
QMessageBox::warning( this, tr( "SVG export error" ),
@@ -3099,7 +3099,7 @@ void QgsComposer::on_mActionSaveAsTemplate_triggered()
settings.setValue( "UI/lastComposerTemplateDir", saveFileInfo.absolutePath() );

QFile templateFile( saveFileName );
if ( !templateFile.open( QIODevice::WriteOnly ) )
if ( !templateFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
return;
}
@@ -4068,7 +4068,7 @@ void QgsComposer::createComposerView()
void QgsComposer::writeWorldFile( const QString& worldFileName, double a, double b, double c, double d, double e, double f ) const
{
QFile worldFile( worldFileName );
if ( !worldFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
if ( !worldFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
{
return;
}
@@ -1229,7 +1229,7 @@ int main( int argc, char *argv[] )
QFile dxfFile;
if ( dxfOutputFile == "-" )
{
if ( !dxfFile.open( stdout, QIODevice::WriteOnly ) )
if ( !dxfFile.open( stdout, QIODevice::WriteOnly | QIODevice::Truncate ) )
{
std::cerr << "could not open stdout" << std::endl;
return 2;
@@ -372,7 +372,7 @@ void QgsBookmarks::exportToXml()
}

QFile f( fileName );
if ( !f.open( QFile::WriteOnly ) )
if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
{
f.close();
return;
@@ -1281,7 +1281,7 @@ void QgsRasterLayerProperties::on_pbnExportTransparentPixelValues_clicked()
}

QFile myOutputFile( myFileName );
if ( myOutputFile.open( QFile::WriteOnly ) )
if ( myOutputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
{
QTextStream myOutputStream( &myOutputFile );
myOutputStream << "# " << tr( "QGIS Generated Transparent Pixel Value Export File" ) << '\n';
@@ -107,7 +107,7 @@ void QgsSubstitutionListWidget::on_mButtonExport_clicked()
doc.appendChild( root );

QFile file( fileName );
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
{
QMessageBox::warning( nullptr, tr( "Export substitutions" ),
tr( "Cannot write file %1:\n%2." ).arg( fileName, file.errorString() ),
@@ -253,7 +253,7 @@ QString QgsAuthCertUtils::pemTextToTempFile( const QString &name, const QByteArr
QFile pemFile( QDir::tempPath() + QDir::separator() + name );
QString pemFilePath( pemFile.fileName() );

if ( pemFile.open( QIODevice::WriteOnly ) )
if ( pemFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
qint64 bytesWritten = pemFile.write( pemtext );
if ( bytesWritten == -1 )
@@ -494,7 +494,7 @@ void QgsApplication::setUITheme( const QString &themeName )

if ( variableInfo.exists() && variablesfile.open( QIODevice::ReadOnly ) )
{
if ( !file.open( QIODevice::ReadOnly ) || !fileout.open( QIODevice::WriteOnly | QIODevice::Text ) )
if ( !file.open( QIODevice::ReadOnly ) || !fileout.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
{
return;
}
@@ -230,7 +230,7 @@ bool QgsRenderChecker::runTest( const QString& theTestName,
//create a world file to go with the image...

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

@@ -34,7 +34,7 @@ bool QgsScaleUtils::saveScaleList( const QString &fileName, const QStringList &s
}

QFile file( fileName );
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
{
errorMessage = QString( "Cannot write file %1:\n%2." ).arg( fileName, file.errorString() );
return false;
@@ -363,7 +363,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
{
QString layerName = vectorFileName.left( vectorFileName.indexOf( ".shp", Qt::CaseInsensitive ) );
QFile prjFile( layerName + ".qpj" );
if ( prjFile.open( QIODevice::WriteOnly ) )
if ( prjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream prjStream( &prjFile );
prjStream << srs.toWkt().toLocal8Bit().constData() << endl;
@@ -1388,7 +1388,7 @@ bool QgsStyle::exportXml( const QString& filename )

// save
QFile f( filename );
if ( !f.open( QFile::WriteOnly ) )
if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
{
mErrorString = "Couldn't open file for writing: " + filename;
return false;
@@ -2950,7 +2950,7 @@ QMimeData* QgsSymbolLayerUtils::colorListToMimeData( const QgsNamedColorList& co

bool QgsSymbolLayerUtils::saveColorsToGpl( QFile &file, const QString& paletteName, const QgsNamedColorList& colors )
{
if ( !file.open( QIODevice::ReadWrite ) )
if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
return false;
}
@@ -139,7 +139,7 @@ void QgsConfigureShortcutsDialog::saveShortcuts()
}

QFile file( fileName );
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
{
QMessageBox::warning( this, tr( "Saving shortcuts" ),
tr( "Cannot write file %1:\n%2." )
@@ -133,7 +133,7 @@ void QgsManageConnectionsDialog::doExportImport()
}

QFile file( mFileName );
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
{
QMessageBox::warning( this, tr( "Saving connections" ),
tr( "Cannot write file %1:\n%2." )
@@ -782,7 +782,7 @@ void QgsMapCanvas::saveAsImage( const QString& theFileName, QPixmap * theQPixmap
QString myWorldFileName = myInfo.absolutePath() + '/' + myInfo.baseName() + '.'
+ outputSuffix.at( 0 ) + outputSuffix.at( myInfo.suffix().size() - 1 ) + 'w';
QFile myWorldFile( myWorldFileName );
if ( !myWorldFile.open( QIODevice::WriteOnly ) ) //don't use QIODevice::Text
if ( !myWorldFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) //don't use QIODevice::Text
{
return;
}
@@ -379,7 +379,7 @@ void QgsSearchQueryBuilder::saveQuery()
}

QFile saveFile( saveFileName );
if ( !saveFile.open( QIODevice::WriteOnly ) )
if ( !saveFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QMessageBox::critical( nullptr, tr( "Error" ), tr( "Could not open file for writing" ) );
return;
@@ -251,7 +251,7 @@ void QgsRasterTransparencyWidget::on_pbnExportTransparentPixelValues_clicked()
}

QFile myOutputFile( myFileName );
if ( myOutputFile.open( QFile::WriteOnly ) )
if ( myOutputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
{
QTextStream myOutputStream( &myOutputFile );
myOutputStream << "# " << tr( "QGIS Generated Transparent Pixel Value Export File" ) << '\n';
@@ -670,7 +670,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
}

QFile outputFile( fileName );
if ( outputFile.open( QFile::WriteOnly ) )
if ( outputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
{
QTextStream outputStream( &outputFile );
outputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << '\n';
@@ -1280,7 +1280,7 @@ bool QgsGeorefPluginGui::loadGCPs( /*bool verbose*/ )
void QgsGeorefPluginGui::saveGCPs()
{
QFile pointFile( mGCPpointsFileName );
if ( pointFile.open( QIODevice::WriteOnly ) )
if ( pointFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream points( &pointFile );
points << "mapX,mapY,pixelX,pixelY,enable" << endl;
@@ -1422,7 +1422,7 @@ bool QgsGeorefPluginGui::writeWorldFile( const QgsPoint& origin, double pixelXSi
{
// write the world file
QFile file( mWorldFileName );
if ( !file.open( QIODevice::WriteOnly ) )
if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
mMessageBar->pushMessage( tr( "Error" ), tr( "Could not write to %1." ).arg( mWorldFileName ), QgsMessageBar::CRITICAL, messageTimeout() );
return false;
@@ -1052,7 +1052,7 @@ void QgsGrassMapcalc::save()
+ "/mapcalc/" + mFileName;

QFile out( path );
if ( !out.open( QIODevice::WriteOnly ) )
if ( !out.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QMessageBox::warning( this, tr( "Save mapcalc" ),
tr( "Cannot open mapcalc file" ) );
@@ -249,7 +249,7 @@ void QgsRasterTerrainAnalysisDialog::on_mExportColorsButton_clicked()
}

QFile outputFile( file );
if ( !outputFile.open( QIODevice::WriteOnly ) )
if ( !outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
return;
}
@@ -203,7 +203,7 @@ bool QgsGPXProvider::addFeatures( QgsFeatureList & flist )

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

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

// write back to file
QFile file( mFileName );
if ( !file.open( QIODevice::WriteOnly ) )
if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
return false;
QTextStream ostr( &file );
data->writeXml( ostr );
@@ -74,7 +74,7 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
char* pszOutWkt = nullptr;
OSRExportToWkt( hSRS, &pszOutWkt );
QFile prjFile( layerName + ".prj" );
if ( prjFile.open( QIODevice::WriteOnly ) )
if ( prjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream prjStream( &prjFile );
prjStream << pszOutWkt << endl;
@@ -90,7 +90,7 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )

// save qgis-specific .qpj file (maybe because of better wkt compatibility?)
QFile qpjFile( layerName + ".qpj" );
if ( qpjFile.open( QIODevice::WriteOnly ) )
if ( qpjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream qpjStream( &qpjFile );
qpjStream << wkt.toLocal8Bit().data() << endl;
@@ -2663,7 +2663,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
{
QString layerName = uri.left( uri.indexOf( ".shp", Qt::CaseInsensitive ) );
QFile prjFile( layerName + ".qpj" );
if ( prjFile.open( QIODevice::WriteOnly ) )
if ( prjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream prjStream( &prjFile );
prjStream << myWkt.toLocal8Bit().data() << endl;
@@ -427,7 +427,7 @@ bool QgsWcsCapabilities::parseCapabilitiesDom( QByteArray const &xml, QgsWcsCapa
QgsDebugMsg( "Entered." );
#ifdef QGISDEBUG
QFile file( QDir::tempPath() + "/qgis-wcs-capabilities.xml" );
if ( file.open( QIODevice::WriteOnly ) )
if ( file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
file.write( xml );
file.close();
@@ -904,7 +904,7 @@ void QgsWFSFeatureIterator::featureReceivedSynchronous( QVector<QgsWFSFeatureGml
mWriterFilename = QDir( QgsWFSUtils::acquireCacheDirectory() ).filePath( QString( "iterator_%1_%2.bin" ).arg( thisStr ).arg( mCounter ) );
QgsDebugMsg( QString( "Transferring feature iterator cache to %1" ).arg( mWriterFilename ) );
mWriterFile = new QFile( mWriterFilename );
if ( !mWriterFile->open( QIODevice::WriteOnly ) )
if ( !mWriterFile->open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QgsDebugMsg( QString( "Cannot open %1 for writing" ).arg( mWriterFilename ) );
delete mWriterFile;
@@ -354,7 +354,7 @@ bool QgsWFSSharedData::createCache()

// Copy the in-memory template Spatialite DB into the target DB
QFile dbFile( mCacheDbname );
if ( !dbFile.open( QIODevice::WriteOnly ) )
if ( !dbFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QgsMessageLog::logMessage( tr( "Cannot create temporary SpatiaLite cache" ), tr( "WFS" ) );
return false;
@@ -249,7 +249,7 @@ bool QgsWmsCapabilities::parseCapabilitiesDom( QByteArray const &xml, QgsWmsCapa

#ifdef QGISDEBUG
QFile file( QDir::tempPath() + "/qgis-wmsprovider-capabilities.xml" );
if ( file.open( QIODevice::WriteOnly ) )
if ( file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
file.write( xml );
file.close();
@@ -3835,7 +3835,7 @@ void QgsWmsTiledImageDownloadHandler::tileReplyFinished()
.arg( reply->url().toString() ), tr( "WMS" ) );
#ifdef QGISDEBUG
QFile file( QDir::tempPath() + "/broken-image.png" );
if ( file.open( QIODevice::WriteOnly ) )
if ( file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
file.write( text );
file.close();
@@ -70,7 +70,7 @@ QString QgsMSUtils::createTempFilePath()
int QgsMSUtils::createTextFile( const QString& filePath, const QString& text )
{
QFile file( filePath );
if ( file.open( QIODevice::WriteOnly | QIODevice::Text ) )
if ( file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
{
QTextStream fileStream( &file );
fileStream << text;
@@ -768,7 +768,7 @@ int QgsSOAPRequestHandler::setUrlToFile( QImage* img )
theFile.setFileName( tmpMasDir.absolutePath() + "/" + folderName + "/map.png" );
uri.append( "/mas_tmp/" + folderName + "/map.png" );
}
if ( !theFile.open( QIODevice::WriteOnly ) )
if ( !theFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QgsDebugMsg( "Error, could not open file" );
return 4;
@@ -335,7 +335,7 @@ QString QgsBench::serialize( const QMap<QString, QVariant>& theMap, int level )
void QgsBench::saveLog( const QString & fileName )
{
QFile file( fileName );
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
return;

QTextStream out( &file );
@@ -57,7 +57,7 @@ void TestQgis::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly ) )
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
@@ -105,7 +105,7 @@ void TestQgsAuthManager::initTestCase()
// create QGIS_AUTH_PASSWORD_FILE file
QString passfilepath = mTempDir + "/passfile";
QFile passfile( passfilepath );
if ( passfile.open( QIODevice::WriteOnly | QIODevice::Text ) )
if ( passfile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
{
QTextStream fout( &passfile );
fout << QString( mPass ) << "\r\n";
@@ -149,7 +149,7 @@ void TestQgsAuthManager::cleanupTestCase()

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

0 comments on commit 06d2d79

Please sign in to comment.
You can’t perform that action at this time.