SaveFile: Fix error handling when moving file with new contents fails

The original content is moved to a backup, then the new file is moved
into its place. If that second step fails, we have to at least try
to move the backup back into the original place, and definitely
not remove the backup.

This behavior changed in 0dafe5cb8c

Task-number: QTCREATORBUG-21724
Change-Id: I996098576c0ceed59dd7359ac4f1b9d33f87d596
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-12-17 09:18:57 +01:00
parent 18bee3a08f
commit 40f2f99714

View File

@@ -186,7 +186,8 @@ bool SaveFile::commit()
const QString &renameError = m_tempFile->errorString(); const QString &renameError = m_tempFile->errorString();
m_tempFile->remove(); m_tempFile->remove();
setErrorString(renameError); setErrorString(renameError);
result = false; QFile::rename(backupName, finalFileName); // rollback to backup if possible ...
return false; // ... or keep the backup copy at least
} }
QFile::remove(backupName); QFile::remove(backupName);