Commit 3f865a87 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

pk: Save the accepted eulas so they don't need to be accepted every time

We save them with a sha of the contents in case they change.

BUG: 431871
parent 5af0d8b0
......@@ -8,6 +8,7 @@
#include "PackageKitBackend.h"
#include "PackageKitResource.h"
#include "PackageKitMessages.h"
#include "PackageKitUpdater.h"
#include "utils.h"
#include "LocalFilePKResource.h"
#include "libdiscover_backend_debug.h"
......@@ -111,8 +112,6 @@ void PKTransaction::statusChanged()
progressChanged();
}
int percentageWithStatus(PackageKit::Transaction::Status status, uint percentage);
void PKTransaction::progressChanged()
{
auto percent = m_trans->percentage();
......@@ -260,12 +259,14 @@ PackageKit::Transaction* PKTransaction::transaction()
void PKTransaction::eulaRequired(const QString& eulaID, const QString& packageID, const QString& vendor, const QString& licenseAgreement)
{
m_proceedFunctions << [eulaID](){
return PackageKit::Daemon::acceptEula(eulaID);
};
Q_EMIT proceedRequest(i18n("Accept EULA"), i18n("The package %1 and its vendor %2 require that you accept their license:\n %3",
const auto handle = handleEula(eulaID, licenseAgreement);
m_proceedFunctions << handle.proceedFunction;
if (handle.request) {
Q_EMIT proceedRequest(i18n("Accept EULA"), i18n("The package %1 and its vendor %2 require that you accept their license:\n %3",
PackageKit::Daemon::packageName(packageID), vendor, licenseAgreement));
} else {
proceed();
}
}
void PKTransaction::errorFound(PackageKit::Transaction::Error err, const QString& error)
......
......@@ -10,8 +10,11 @@
#include <PackageKit/Offline>
#include <QDebug>
#include <QSet>
#include <QCryptographicHash>
#include <KLocalizedString>
#include <KSharedConfig>
#include <KConfigGroup>
#include "libdiscover_backend_debug.h"
#include "utils.h"
......@@ -443,13 +446,41 @@ void PackageKitUpdater::mediaChange(PackageKit::Transaction::MediaType media, co
Q_EMIT passiveMessage(i18n("Media Change of type '%1' is requested.\n%2", type, text));
}
EulaHandling handleEula(const QString& eulaID, const QString& licenseAgreement)
{
KConfigGroup group(KSharedConfig::openConfig(), "EULA");
auto licenseGroup = group.group(eulaID);
QCryptographicHash hash(QCryptographicHash::Sha256);
hash.addData(licenseAgreement.toUtf8());
QByteArray hashHex = hash.result().toHex();
EulaHandling ret;
ret.request = licenseGroup.readEntry("Hash", QByteArray()) != hashHex;
if (!ret.request) {
ret.proceedFunction = [eulaID] {
return PackageKit::Daemon::acceptEula(eulaID);
};
} else {
ret.proceedFunction = [eulaID, hashHex] {
KConfigGroup group(KSharedConfig::openConfig(), "EULA");
KConfigGroup licenseGroup = group.group(eulaID);
licenseGroup.writeEntry<QByteArray>("Hash", hashHex);
return PackageKit::Daemon::acceptEula(eulaID);
};
}
return ret;
}
void PackageKitUpdater::eulaRequired(const QString& eulaID, const QString& packageID, const QString& vendor, const QString& licenseAgreement)
{
m_proceedFunctions << [eulaID](){
return PackageKit::Daemon::acceptEula(eulaID);
};
Q_EMIT proceedRequest(i18n("Accept EULA"), i18n("The package %1 and its vendor %2 require that you accept their license:\n %3",
const auto handle = handleEula(eulaID, licenseAgreement);
m_proceedFunctions << handle.proceedFunction;
if (handle.request) {
Q_EMIT proceedRequest(i18n("Accept EULA"), i18n("The package %1 and its vendor %2 require that you accept their license:\n %3",
PackageKit::Daemon::packageName(packageID), vendor, licenseAgreement));
} else {
proceed();
}
}
void PackageKitUpdater::setProgressing(bool progressing)
......
......@@ -12,6 +12,11 @@
class SystemUpgrade;
struct EulaHandling {
std::function<PackageKit::Transaction*()> proceedFunction;
bool request = false;
};
EulaHandling handleEula(const QString& eulaID, const QString& licenseAgreement);
int percentageWithStatus(PackageKit::Transaction::Status status, uint percentage);
class PackageKitUpdater : public AbstractBackendUpdater
......
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