1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

feat(database): make a backup before upgrading

If anything is wrong with the newly encrypted db this will save the
data.
This commit is contained in:
sudden6 2016-11-21 21:46:26 +01:00
parent c4b9d302d0
commit c1d471faa1
No known key found for this signature in database
GPG Key ID: 279509B499E032B9

View File

@ -110,18 +110,30 @@ RawDatabase::RawDatabase(const QString& path, const QString& password, const QBy
// avoid opening the same db twice
close();
// create a backup before trying to upgrade to new salt
bool upgrade = true;
if(!QFile::copy(path, path + ".bak"))
{
qDebug() << "Couldn't create the backup of the database, won't upgrade";
upgrade = false;
}
// fall back to the old salt
currentHexKey = deriveKey(password);
if(open(path, currentHexKey))
{
// still using old salt, upgrade
if(setPassword(password))
// upgrade only if backup successful
if(upgrade)
{
qDebug() << "Successfully upgraded to dynamic salt";
}
else
{
qWarning() << "Failed to set password with new salt";
// still using old salt, upgrade
if(setPassword(password))
{
qDebug() << "Successfully upgraded to dynamic salt";
}
else
{
qWarning() << "Failed to set password with new salt";
}
}
}
else