diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2021-08-20 15:25:41 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2021-08-23 13:16:01 +0300 |
commit | 48c76e8e227f86bd7ecce662ec281d5705c865b5 (patch) | |
tree | 5cee8370ce8a4973dcdede2c177142dbeadd19a0 /src/libsync | |
parent | 8aad08384382e770688402d168ccdab0847dc5ae (diff) |
Clean up migration code too
Diffstat (limited to 'src/libsync')
-rw-r--r-- | src/libsync/creds/httpcredentials.cpp | 6 | ||||
-rw-r--r-- | src/libsync/creds/httpcredentials_p.h | 41 |
2 files changed, 21 insertions, 26 deletions
diff --git a/src/libsync/creds/httpcredentials.cpp b/src/libsync/creds/httpcredentials.cpp index 9165cff6e..f99830e7d 100644 --- a/src/libsync/creds/httpcredentials.cpp +++ b/src/libsync/creds/httpcredentials.cpp @@ -185,9 +185,9 @@ void HttpCredentials::fetchFromKeychainHelper() Q_ASSERT(!_user.isEmpty()); const int version = _account->credentialSetting(CredentialVersionKey()).toInt(); if (version < CredentialVersion && !_credentialMigration) { - auto mirgration = new HttpLegacyCredentials(this); - _credentialMigration = mirgration; - mirgration->fetchFromKeychainHelper(); + auto migration = new HttpLegacyCredentials(this); + _credentialMigration = migration; + migration->fetchFromKeychainHelper(); return; } diff --git a/src/libsync/creds/httpcredentials_p.h b/src/libsync/creds/httpcredentials_p.h index 779b4b4fd..ed9b7fc40 100644 --- a/src/libsync/creds/httpcredentials_p.h +++ b/src/libsync/creds/httpcredentials_p.h @@ -126,6 +126,7 @@ private: void slotReadJobDone(QKeychain::Job *incoming) { + Q_ASSERT(!_parent->_user.isEmpty()); auto job = qobject_cast<QKeychain::ReadPasswordJob *>(incoming); QKeychain::Error error = job->error(); @@ -139,36 +140,30 @@ private: return; } - bool isOauth = _parent->_account->credentialSetting(isOAuthC()).toBool(); - if (isOauth) { - _parent->_refreshToken = job->textData(); - } else { - _parent->_password = job->textData(); - } - - if (_parent->_user.isEmpty()) { - qCWarning(lcHttpLegacyCredentials) << "Strange: User is empty!"; - } - - if (!_parent->_refreshToken.isEmpty() && error == QKeychain::NoError) { - _parent->refreshAccessToken(); - } else if (!_parent->_password.isEmpty() && error == QKeychain::NoError) { - // All cool, the keychain did not come back with error. - // Still, the password can be empty which indicates a problem and - // the password dialog has to be opened. - _parent->_ready = true; - emit _parent->fetched(); - } else { + const auto data = job->textData(); + if (error != QKeychain::NoError || data.isEmpty()) { // we come here if the password is empty or any other keychain // error happend. - + qCWarning(lcHttpLegacyCredentials) << "Migrating old keychain entries failed" << job->errorString(); _parent->_fetchErrorString = job->error() != QKeychain::EntryNotFound ? job->errorString() : QString(); - _parent->_password = QString(); + _parent->_password.clear(); _parent->_ready = false; emit _parent->fetched(); + } else { + qCWarning(lcHttpLegacyCredentials) << "Migrated old keychain entries"; + if (_parent->_account->credentialSetting(isOAuthC()).toBool()) { + _parent->_refreshToken = data; + _parent->refreshAccessToken(); + } else { + // All cool, the keychain did not come back with error. + // Still, the password can be empty which indicates a problem and + // the password dialog has to be opened. + _parent->_password = data; + _parent->_ready = true; + emit _parent->fetched(); + } } - // If keychain data was read from legacy location, wipe these entries and store new ones deleteOldKeychainEntries(); if (_parent->_ready) { |