Commit ab019c74 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

pk: Keep the same instance of SystemUpgrade across PackageKitUpdate lifetime

Instead of creating a new one when preparing a new update. It would get
confused and crash sometimes. Not pretty.
parent a5d74c7a
......@@ -56,9 +56,8 @@ static void kRemoveDuplicates(QJsonArray & input, std::function<QString(const QJ
class SystemUpgrade : public AbstractResource
{
public:
SystemUpgrade(const QSet<AbstractResource*> &resources, PackageKitBackend* backend)
SystemUpgrade(PackageKitBackend* backend)
: AbstractResource(backend)
, m_resources(resources)
, m_backend(backend)
{
for (auto res : qAsConst(m_resources)) {
......@@ -133,8 +132,12 @@ public:
return ret;
}
void setCandidates(const QSet<AbstractResource*> &candidates) {
m_resources = candidates;
}
private:
const QSet<AbstractResource*> m_resources;
QSet<AbstractResource*> m_resources;
PackageKitBackend* const m_backend;
};
......@@ -145,7 +148,8 @@ PackageKitUpdater::PackageKitUpdater(PackageKitBackend * parent)
m_isCancelable(false),
m_isProgressing(false),
m_percentage(0),
m_lastUpdate()
m_lastUpdate(),
m_upgrade(new SystemUpgrade(m_backend))
{
fetchLastUpdateTime();
}
......@@ -166,7 +170,9 @@ void PackageKitUpdater::prepare()
Q_ASSERT(!m_transaction);
const auto candidates = m_backend->upgradeablePackages();
if (useOfflineUpdates() && !candidates.isEmpty()) {
m_toUpgrade = { new SystemUpgrade(candidates, m_backend) };
m_upgrade->setCandidates(candidates);
m_toUpgrade = { m_upgrade };
} else {
m_toUpgrade = candidates;
}
......
......@@ -10,6 +10,8 @@
#include "PackageKitBackend.h"
#include <PackageKit/Transaction>
class SystemUpgrade;
int percentageWithStatus(PackageKit::Transaction::Status status, uint percentage);
class PackageKitUpdater : public AbstractBackendUpdater
......@@ -87,6 +89,8 @@ class PackageKitUpdater : public AbstractBackendUpdater
QDateTime m_lastUpdate;
QMap<PackageKit::Transaction::Info, QStringList> m_packagesModified;
QVector<std::function<PackageKit::Transaction*()>> m_proceedFunctions;
SystemUpgrade* m_upgrade = nullptr;
};
......
Markdown is supported
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