Browse Source

feat(database): make a backup before upgrading

If anything is wrong with the newly encrypted db this will save the
data.
reviewable/pr3827/r12
sudden6 9 years ago
parent
commit
c1d471faa1
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
  1. 26
      src/persistence/db/rawdatabase.cpp

26
src/persistence/db/rawdatabase.cpp

@ -110,18 +110,30 @@ RawDatabase::RawDatabase(const QString& path, const QString& password, const QBy @@ -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))
{
qDebug() << "Successfully upgraded to dynamic salt";
}
else
// upgrade only if backup successful
if(upgrade)
{
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

Loading…
Cancel
Save