Skip to content

Commit

Permalink
use existing files when saving existing project
Browse files Browse the repository at this point in the history
  • Loading branch information
SebDieBln committed Dec 25, 2015
1 parent 036eada commit 7c3cf64
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7c3cf64

Please sign in to comment.