Commit 3db02510 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Don't start runJob() loop if the access token is not available.

Otherwise the loop will go on forever, attempting to start jobs that
will never work.

KAccounts seems to return an empty access token when google returns
a 401 error (access code expired).

CCBUG: 391186
parent 39f110c0
Pipeline #232746 passed with stage
in 35 seconds
......@@ -135,5 +135,8 @@ KIO::UDSEntry GDriveHelper::trash()
QString GDriveHelper::elideToken(const QString &token)
{
if (token.isEmpty()) {
return {};
}
return token.mid(0, 30).append(QStringLiteral("..."));
}
......@@ -153,6 +153,9 @@ AccountPtr KAccountsManager::getAccountCredentials(Accounts::AccountId id, const
{
auto job = new GetCredentialsJob(id, nullptr);
job->exec();
if (job->error()) {
qCWarning(GDRIVE) << "GetCredentialsJob failed:" << job->errorString();
}
auto gapiAccount = AccountPtr(new Account(displayName,
job->credentialsData().value(QStringLiteral("AccessToken")).toString(),
......
......@@ -1016,6 +1016,13 @@ bool KIOGDrive::readPutData(QTemporaryFile &tempFile, FilePtr &fileMetaData)
bool KIOGDrive::runJob(KGAPI2::Job &job, const QUrl &url, const QString &accountId)
{
auto account = getAccount(accountId);
if (account->accessToken().isEmpty()) {
qCWarning(GDRIVE) << "Expired or missing access/refresh token for account" << accountId;
error(KIO::ERR_WORKER_DEFINED, i18n("Expired or missing access tokens for account %1", accountId));
return false;
}
KIOGDrive::Action action = KIOGDrive::Fail;
Q_FOREVER {
qCDebug(GDRIVE) << "Running job" << (&job) << "with accessToken" << GDriveHelper::elideToken(job.account()->accessToken());
......@@ -1029,7 +1036,7 @@ bool KIOGDrive::runJob(KGAPI2::Job &job, const QUrl &url, const QString &account
} else if (action == KIOGDrive::Fail) {
return false;
}
job.setAccount(getAccount(accountId));
job.setAccount(account);
job.restart();
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment