Skip to content
Permalink
Browse files

use existing files when saving existing project

  • Loading branch information
SebDieBln committed Dec 22, 2015
1 parent 036eada commit 7c3cf646e884e37674391da4e431140392794106
Showing with 17 additions and 6 deletions.
  1. +17 −6 src/core/qgsproject.cpp
@@ -1005,19 +1005,30 @@ bool QgsProject::write()
// Create backup file
if ( QFile::exists( fileName() ) )
{
QString backup = fileName() + '~';
if ( QFile::exists( backup ) )
QFile::remove( backup );
QFile backupFile( fileName() + '~' );
bool ok = true;
ok &= backupFile.open( QIODevice::WriteOnly | QIODevice::Truncate );
ok &= imp_->file.open( QIODevice::ReadOnly );

if ( !QFile::copy( fileName(), backup ) )
QByteArray ba;
while ( ok && !imp_->file.atEnd() )
{
ba = imp_->file.read( 10240 );
ok &= backupFile.write( ba ) == ba.size();
}

imp_->file.close();
backupFile.close();

if ( !ok )
{
setError( tr( "Unable to create backup file %1" ).arg( backup ) );
setError( tr( "Unable to create backup file %1" ).arg( backupFile.fileName() ) );
return false;
}

QFileInfo fi( fileName() );
struct utimbuf tb = { fi.lastRead().toTime_t(), fi.lastModified().toTime_t() };
utime( backup.toUtf8().constData(), &tb );
utime( backupFile.fileName().toUtf8().constData(), &tb );
}

// if we have problems creating or otherwise writing to the project file,

0 comments on commit 7c3cf64

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