Commit 3b433105 authored by Oleg Solovyov's avatar Oleg Solovyov 🐴
Browse files

packagekit: check free space when update size changes

copied logic from c01a0cee
parent ba8df866
......@@ -59,14 +59,20 @@ static void kRemoveDuplicates(QJsonArray &input, std::function<QString(const QJs
class SystemUpgrade : public AbstractResource
{
Q_OBJECT
public:
SystemUpgrade(PackageKitBackend *backend)
: AbstractResource(backend)
, m_backend(backend)
, m_updateSizeTimer(new QTimer(this))
{
connect(m_backend, &AbstractResourcesBackend::resourceRemoved, this, [this](AbstractResource *res) {
m_resources.remove(res);
});
m_updateSizeTimer->setInterval(100);
m_updateSizeTimer->setSingleShot(true);
connect(m_updateSizeTimer, &QTimer::timeout, this, &SystemUpgrade::updateSizeChanged);
}
QString packageName() const override
......@@ -221,6 +227,7 @@ public:
void refreshResource()
{
Q_EMIT m_backend->resourcesChanged(this, {"size", "license"});
m_updateSizeTimer->start();
}
void setCandidates(const QSet<AbstractResource *> &candidates)
......@@ -239,9 +246,13 @@ public:
}
}
Q_SIGNALS:
void updateSizeChanged();
private:
QSet<AbstractResource *> m_resources;
PackageKitBackend *const m_backend;
QTimer *m_updateSizeTimer;
};
PackageKitUpdater::PackageKitUpdater(PackageKitBackend *parent)
......@@ -276,10 +287,17 @@ void PackageKitUpdater::prepare()
m_upgrade->setCandidates(candidates);
m_toUpgrade = {m_upgrade};
connect(m_upgrade, &SystemUpgrade::updateSizeChanged, this, &PackageKitUpdater::checkFreeSpace);
} else {
m_toUpgrade = candidates;
}
checkFreeSpace();
m_allUpgradeable = m_toUpgrade;
}
void PackageKitUpdater::checkFreeSpace()
{
auto j = KIO::fileSystemFreeSpace(QUrl::fromLocalFile("/usr"));
connect(j, &KIO::FileSystemFreeSpaceJob::result, this, [this](KIO::Job * /*job*/, KIO::filesize_t /*size*/, KIO::filesize_t available) {
if (available < updateSize()) {
......@@ -288,7 +306,6 @@ void PackageKitUpdater::prepare()
KFormat().formatByteSize(available)));
}
});
m_allUpgradeable = m_toUpgrade;
}
void PackageKitUpdater::setupTransaction(PackageKit::Transaction::TransactionFlags flags)
......@@ -773,3 +790,5 @@ quint64 PackageKitUpdater::downloadSpeed() const
{
return m_transaction ? m_transaction->speed() : 0;
}
#include "PackageKitUpdater.moc"
......@@ -27,6 +27,7 @@ public:
~PackageKitUpdater() override;
void prepare() override;
void checkFreeSpace();
bool hasUpdates() const override;
qreal progress() const override;
......
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