Move QKeychain::NoBackendAvailable error handling to KeychainChunk class
authorMichael Schuster <michael@schuster.ms>
Wed, 24 Jun 2020 22:30:41 +0000 (00:30 +0200)
committerMichael Schuster <michael@schuster.ms>
Mon, 6 Jul 2020 19:51:36 +0000 (21:51 +0200)
Originally this was in the WebFlowCredentials class. Since we've abstracted everything
from there already, let's also move this in case some other code may use
KeychainChunk::ReadJob prior to WebFlowCredentials.

Signed-off-by: Michael Schuster <michael@schuster.ms>
src/gui/creds/keychainchunk.cpp
src/gui/creds/keychainchunk.h
src/gui/creds/webflowcredentials.cpp
src/gui/creds/webflowcredentials.h

index cd6d3257f2dcce4a41f8db9150c5f9cdfec31322..836be0b01b264c3295f98c7b7b6e347e0681a965 100644 (file)
@@ -202,8 +202,25 @@ void ReadJob::slotReadJobDone(QKeychain::Job *incomingJob)
             }
 #endif
         } else {
-            if (readJob->error() != QKeychain::Error::EntryNotFound ||
-                ((readJob->error() == QKeychain::Error::EntryNotFound) && _chunkCount == 0)) {
+#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
+            if (!readJob->insecureFallback()) { // If insecureFallback is set, the next test would be pointless
+                if (_retryOnKeyChainError && (readJob->error() == QKeychain::NoBackendAvailable
+                        || readJob->error() == QKeychain::OtherError)) {
+                    // Could be that the backend was not yet available. Wait some extra seconds.
+                    // (Issues #4274 and #6522)
+                    // (For kwallet, the error is OtherError instead of NoBackendAvailable, maybe a bug in QtKeychain)
+                    qCInfo(lcKeychainChunk) << "Backend unavailable (yet?) Retrying in a few seconds." << readJob->errorString();
+                    QTimer::singleShot(10000, this, &ReadJob::start);
+                    _retryOnKeyChainError = false;
+                    readJob->deleteLater();
+                    return;
+                }
+                _retryOnKeyChainError = false;
+            }
+#endif
+
+            if (readJob->error() != QKeychain::EntryNotFound ||
+                ((readJob->error() == QKeychain::EntryNotFound) && _chunkCount == 0)) {
                 _error = readJob->error();
                 _errorString = readJob->errorString();
                 qCWarning(lcKeychainChunk) << "Unable to read" << readJob->key() << "chunk" << QString::number(_chunkCount) << readJob->errorString();
index 875ab5037847dc86a46abcc1ded46c9cc840a275..d1ae1e9ddaf119b08cfcc96fcfbc940ba969afdd 100644 (file)
@@ -111,6 +111,11 @@ signals:
 
 private slots:
     void slotReadJobDone(QKeychain::Job *incomingJob);
+
+#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
+private:
+    bool _retryOnKeyChainError = true; // true if we haven't done yet any reading from keychain
+#endif
 }; // class ReadJob
 
 } // namespace KeychainChunk
index ba762ee0cfdc0e1625d69eb56fdfd7321038571a..ff5c2eb2abe3405b5a6dcda63feab14d1a6aaa5f 100644 (file)
@@ -450,21 +450,6 @@ void WebFlowCredentials::fetchFromKeychainHelper() {
 
 void WebFlowCredentials::slotReadClientCertPEMJobDone(KeychainChunk::ReadJob *readJob)
 {
-#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
-    Q_ASSERT(!readJob->insecureFallback()); // If insecureFallback is set, the next test would be pointless
-    if (_retryOnKeyChainError && (readJob->error() == QKeychain::NoBackendAvailable
-            || readJob->error() == QKeychain::OtherError)) {
-        // Could be that the backend was not yet available. Wait some extra seconds.
-        // (Issues #4274 and #6522)
-        // (For kwallet, the error is OtherError instead of NoBackendAvailable, maybe a bug in QtKeychain)
-        qCInfo(lcWebFlowCredentials) << "Backend unavailable (yet?) Retrying in a few seconds." << readJob->errorString();
-        QTimer::singleShot(10000, this, &WebFlowCredentials::fetchFromKeychainHelper);
-        _retryOnKeyChainError = false;
-        return;
-    }
-    _retryOnKeyChainError = false;
-#endif
-
     // Store PEM in memory
     if (readJob->error() == NoError && readJob->binaryData().length() > 0) {
         QList<QSslCertificate> sslCertificateList = QSslCertificate::fromData(readJob->binaryData(), QSsl::Pem);
index 511ab542eadb49f7729a74ed1e7581d8309f1f38..3f9cee38da3ff8a3aafdc11576889b6cefe03935 100644 (file)
@@ -122,7 +122,6 @@ protected:
     bool _ready = false;
     bool _credentialsValid = false;
     bool _keychainMigration = false;
-    bool _retryOnKeyChainError = true; // true if we haven't done yet any reading from keychain
 
     WebFlowCredentialsDialog *_askDialog = nullptr;
 };