Only delete old file when the new one has been saved successfully.

This commit is contained in:
Felix Geyer 2012-04-11 20:34:08 +02:00
parent 7880c0e4f5
commit e39827d777

View File

@ -174,7 +174,7 @@ void DatabaseTabWidget::saveDatabaseAs(Database* db)
QString fileName = fileDialog()->getSaveFileName(m_window, tr("Save database as"), QString fileName = fileDialog()->getSaveFileName(m_window, tr("Save database as"),
oldFileName, tr("KeePass 2 Database").append(" (*.kdbx)")); oldFileName, tr("KeePass 2 Database").append(" (*.kdbx)"));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
delete dbStruct.file; QFile* oldFile = dbStruct.file;
QScopedPointer<QFile> file(new QFile(fileName)); QScopedPointer<QFile> file(new QFile(fileName));
// TODO error handling // TODO error handling
if (!file->open(QIODevice::ReadWrite)) { if (!file->open(QIODevice::ReadWrite)) {
@ -184,6 +184,7 @@ void DatabaseTabWidget::saveDatabaseAs(Database* db)
// TODO ensure that the data is actually written to disk // TODO ensure that the data is actually written to disk
m_writer.writeDatabase(dbStruct.file, db); m_writer.writeDatabase(dbStruct.file, db);
dbStruct.file->flush(); dbStruct.file->flush();
delete oldFile;
dbStruct.modified = false; dbStruct.modified = false;
dbStruct.fileName = QFileInfo(fileName).absoluteFilePath(); dbStruct.fileName = QFileInfo(fileName).absoluteFilePath();