summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2018-06-21 23:58:01 +0200
committerAleix Pol <[email protected]>2018-06-22 00:39:59 +0200
commit7bae1c831f0cb63a643949eab626da38cc7105f8 (patch)
tree30363a3f4d77b2ed9942abdeb9d217623d7bcdf4
parentc0b69142bbe01861b07a6d736af114913dbc51c2 (diff)
Trigger a refresh when appstream data isn't available when on aptcc
On Debian (at least) we don't get appstream information until apt-get update (or equivalent) is called.
-rw-r--r--libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp41
-rw-r--r--libdiscover/backends/PackageKitBackend/PackageKitBackend.h2
2 files changed, 26 insertions, 17 deletions
diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp
index 4445297..fd36552 100644
--- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp
+++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp
@@ -72,6 +72,7 @@ QString PackageKitBackend::locateService(const QString &filename)
PackageKitBackend::PackageKitBackend(QObject* parent)
: AbstractResourcesBackend(parent)
+ , m_appdata(new AppStream::Pool)
, m_updater(new PackageKitUpdater(this))
, m_refresher(nullptr)
, m_isFetching(0)
@@ -93,19 +94,8 @@ PackageKitBackend::PackageKitBackend(QObject* parent)
SourcesModel::global()->addSourcesBackend(new PackageKitSourcesBackend(this));
-
- QString error;
- const bool b = m_appdata.load(&error);
reloadPackageList();
- if (!b && m_packages.packages.isEmpty()) {
- qWarning() << "Could not open the AppStream metadata pool" << error;
-
- QTimer::singleShot(0, this, [this]() {
- Q_EMIT passiveMessage(i18n("Please make sure that Appstream is properly set up on your system"));
- });
- }
-
setWhenAvailable(PackageKit::Daemon::getTimeSinceAction(PackageKit::Transaction::RoleRefreshCache), [this](uint timeSince) {
if (timeSince > 3600)
checkForUpdates();
@@ -139,7 +129,18 @@ void PackageKitBackend::reloadPackageList()
disconnect(m_refresher.data(), &PackageKit::Transaction::finished, this, &PackageKitBackend::reloadPackageList);
}
- const auto components = m_appdata.components();
+ QString error;
+ m_appdata.reset(new AppStream::Pool);
+ const bool b = m_appdata->load(&error);
+ if (!b && m_packages.packages.isEmpty()) {
+ qWarning() << "Could not open the AppStream metadata pool" << error;
+
+ QTimer::singleShot(0, this, [this]() {
+ Q_EMIT passiveMessage(i18n("Please make sure that Appstream is properly set up on your system"));
+ });
+ }
+
+ const auto components = m_appdata->components();
QStringList neededPackages;
neededPackages.reserve(components.size());
foreach(const AppStream::Component& component, components) {
@@ -181,8 +182,15 @@ void PackageKitBackend::reloadPackageList()
}
acquireFetching(false);
- neededPackages.removeDuplicates();
- resolvePackages(neededPackages);
+ if (!neededPackages.isEmpty()) {
+ neededPackages.removeDuplicates();
+ resolvePackages(neededPackages);
+ } else {
+ qDebug() << "empty appstream db";
+ if (PackageKit::Daemon::backendName() == QLatin1String("aptcc") || PackageKit::Daemon::backendName().isEmpty()) {
+ checkForUpdates();
+ }
+ }
}
AppPackageKitResource* PackageKitBackend::addComponent(const AppStream::Component& component, const QStringList& pkgNames)
@@ -355,6 +363,7 @@ void PackageKitBackend::checkForUpdates()
m_refresher = PackageKit::Daemon::refreshCache(false);
connect(m_refresher.data(), &PackageKit::Transaction::errorCode, this, &PackageKitBackend::transactionError);
connect(m_refresher.data(), &PackageKit::Transaction::finished, this, [this]() {
+ m_refresher = nullptr;
reloadPackageList();
acquireFetching(false);
});
@@ -365,7 +374,7 @@ void PackageKitBackend::checkForUpdates()
QList<AppStream::Component> PackageKitBackend::componentsById(const QString& id) const
{
- return m_appdata.componentsById(id);
+ return m_appdata->componentsById(id);
}
ResultsStream* PackageKitBackend::search(const AbstractResourcesBackend::Filters& filter)
@@ -378,7 +387,7 @@ ResultsStream* PackageKitBackend::search(const AbstractResourcesBackend::Filters
} else if (filter.search.isEmpty()) {
return new ResultsStream(QStringLiteral("PackageKitStream-all"), kFilter<QVector<AbstractResource*>>(m_packages.packages, [](AbstractResource* res) { return !res->isTechnical(); }));
} else {
- const QList<AppStream::Component> components = m_appdata.search(filter.search);
+ const QList<AppStream::Component> components = m_appdata->search(filter.search);
const QStringList ids = kTransform<QStringList>(components, [](const AppStream::Component& comp) { return comp.id(); });
auto stream = new ResultsStream(QStringLiteral("PackageKitStream-search"));
if (!ids.isEmpty()) {
diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h
index 5972650..b08e596 100644
--- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h
+++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h
@@ -101,7 +101,7 @@ class DISCOVERCOMMON_EXPORT PackageKitBackend : public AbstractResourcesBackend
void performDetailsFetch();
AppPackageKitResource* addComponent(const AppStream::Component& component, const QStringList& pkgNames);
- AppStream::Pool m_appdata;
+ QScopedPointer<AppStream::Pool> m_appdata;
PackageKitUpdater* m_updater;
QPointer<PackageKit::Transaction> m_refresher;
int m_isFetching;