kde-plasma
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
From dc67ef22f47b9e8b46d668b811982f33600f1aae Mon Sep 17 00:00:00 2001
|
||||
From: Aleix Pol <aleixpol@kde.org>
|
||||
Date: Wed, 10 Nov 2021 01:55:56 +0100
|
||||
Subject: [PATCH] flatpak: Do not include the resource type in the
|
||||
FlatpakResource::Id
|
||||
|
||||
Otherwise we couldn't make sure that idForInstalledRef() was coherent
|
||||
with FlatpakResource::uniqueId().
|
||||
In the end it's not a problem, it's not like we can have an app and
|
||||
runtime with the same name.
|
||||
|
||||
|
||||
(cherry picked from commit 614450b3ee9175fb16f068af505fb59ed27e6697)
|
||||
---
|
||||
.../FlatpakBackend/FlatpakBackend.cpp | 25 ++++++++-----------
|
||||
.../FlatpakBackend/FlatpakResource.cpp | 12 ++++-----
|
||||
.../backends/FlatpakBackend/FlatpakResource.h | 7 +++---
|
||||
3 files changed, 19 insertions(+), 25 deletions(-)
|
||||
|
||||
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
|
||||
index 012817ef9..6727b0227 100644
|
||||
--- a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
|
||||
+++ b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
|
||||
@@ -149,8 +149,7 @@ QDebug operator<<(QDebug debug, const FlatpakResource::Id &id)
|
||||
QDebugStateSaver saver(debug);
|
||||
debug.nospace() << "FlatpakResource::Id(";
|
||||
debug.nospace() << "name:" << id.id << ',';
|
||||
- debug.nospace() << "branch:" << id.branch << ',';
|
||||
- debug.nospace() << "type:" << id.type;
|
||||
+ debug.nospace() << "branch:" << id.branch;
|
||||
debug.nospace() << ')';
|
||||
return debug;
|
||||
}
|
||||
@@ -162,7 +161,6 @@ static FlatpakResource::Id idForRefString(const QStringView &ref)
|
||||
auto parts = ref.split('/');
|
||||
// app/app.getspace.Space/x86_64/stable
|
||||
return {
|
||||
- parts[0] == QLatin1String("app") ? FlatpakResource::DesktopApp : FlatpakResource::Runtime,
|
||||
parts[1].toString(),
|
||||
parts[3].toString(),
|
||||
parts[2].toString(),
|
||||
@@ -178,7 +176,7 @@ static FlatpakResource::Id idForInstalledRef(FlatpakInstalledRef *ref, const QSt
|
||||
const QString arch = QString::fromUtf8(flatpak_ref_get_arch(FLATPAK_REF(ref)));
|
||||
const QString branch = QString::fromUtf8(flatpak_ref_get_branch(FLATPAK_REF(ref)));
|
||||
|
||||
- return {appType, appId, branch, arch};
|
||||
+ return {appId, branch, arch};
|
||||
}
|
||||
|
||||
FlatpakBackend::FlatpakBackend(QObject *parent)
|
||||
@@ -350,25 +348,20 @@ QString refToBundleId(FlatpakRef *ref)
|
||||
|
||||
FlatpakResource *FlatpakBackend::getAppForInstalledRef(FlatpakInstallation *installation, FlatpakInstalledRef *ref) const
|
||||
{
|
||||
- auto id = idForInstalledRef(ref, {});
|
||||
- for (const auto &source : m_flatpakSources) {
|
||||
- auto ret = source->m_resources.value(id);
|
||||
+ const QString origin = QString::fromUtf8(flatpak_installed_ref_get_origin(ref));
|
||||
+ auto source = findSource(installation, origin);
|
||||
+ if (source) {
|
||||
+ auto ret = source->m_resources.value(idForInstalledRef(ref, {}));
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
- }
|
||||
- auto id2 = idForInstalledRef(ref, QStringLiteral(".desktop"));
|
||||
- for (const auto &source : m_flatpakSources) {
|
||||
- auto ret = source->m_resources.value(id2);
|
||||
+ ret = source->m_resources.value(idForInstalledRef(ref, QStringLiteral(".desktop")));
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
const QLatin1String name(flatpak_ref_get_name(FLATPAK_REF(ref)));
|
||||
-
|
||||
- const QString origin = QString::fromUtf8(flatpak_installed_ref_get_origin(ref));
|
||||
- auto source = findSource(installation, origin);
|
||||
const QString pathExports = FlatpakResource::installationPath(installation) + QLatin1String("/exports/");
|
||||
const QString pathApps = pathExports + QLatin1String("share/applications/");
|
||||
AppStream::Component cid;
|
||||
@@ -413,6 +406,8 @@ FlatpakResource *FlatpakBackend::getAppForInstalledRef(FlatpakInstallation *inst
|
||||
resource->updateFromRef(FLATPAK_REF(ref));
|
||||
resource->setState(AbstractResource::Installed);
|
||||
source->addResource(resource);
|
||||
+
|
||||
+ Q_ASSERT(resource->uniqueId() == idForInstalledRef(ref, {}) || resource->uniqueId() == idForInstalledRef(ref, {".desktop"}));
|
||||
return resource;
|
||||
}
|
||||
|
||||
@@ -445,7 +440,7 @@ FlatpakResource *FlatpakBackend::getRuntimeForApp(FlatpakResource *resource) con
|
||||
for (const auto &source : m_flatpakSources) {
|
||||
for (auto it = source->m_resources.constBegin(), itEnd = source->m_resources.constEnd(); it != itEnd; ++it) {
|
||||
const auto &id = it.key();
|
||||
- if (id.type == FlatpakResource::Runtime && id.id == runtimeInfo.at(0) && id.branch == runtimeInfo.at(2)) {
|
||||
+ if ((*it)->resourceType() == FlatpakResource::Runtime && id.id == runtimeInfo.at(0) && id.branch == runtimeInfo.at(2)) {
|
||||
runtime = *it;
|
||||
break;
|
||||
}
|
||||
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp b/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
|
||||
index 8f6b25575..7419dcee7 100644
|
||||
--- a/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
|
||||
+++ b/libdiscover/backends/FlatpakBackend/FlatpakResource.cpp
|
||||
@@ -41,7 +41,7 @@ static QString iconCachePath(const AppStream::Icon &icon)
|
||||
FlatpakResource::FlatpakResource(const AppStream::Component &component, FlatpakInstallation *installation, FlatpakBackend *parent)
|
||||
: AbstractResource(parent)
|
||||
, m_appdata(component)
|
||||
- , m_id({FlatpakResource::DesktopApp, component.id(), QString(), QString()})
|
||||
+ , m_id({component.id(), QString(), QString()})
|
||||
, m_downloadSize(0)
|
||||
, m_installedSize(0)
|
||||
, m_propertyStates({{DownloadSize, NotKnownYet}, {InstalledSize, NotKnownYet}, {RequiredRuntime, NotKnownYet}})
|
||||
@@ -122,7 +122,7 @@ QString FlatpakResource::branch() const
|
||||
|
||||
bool FlatpakResource::canExecute() const
|
||||
{
|
||||
- return (m_id.type == DesktopApp && (m_state == AbstractResource::Installed || m_state == AbstractResource::Upgradeable));
|
||||
+ return (m_type == DesktopApp && (m_state == AbstractResource::Installed || m_state == AbstractResource::Upgradeable));
|
||||
}
|
||||
|
||||
void FlatpakResource::updateFromRef(FlatpakRef *ref)
|
||||
@@ -241,7 +241,7 @@ int FlatpakResource::installedSize() const
|
||||
|
||||
AbstractResource::Type FlatpakResource::type() const
|
||||
{
|
||||
- switch (m_id.type) {
|
||||
+ switch (m_type) {
|
||||
case FlatpakResource::Runtime:
|
||||
return Technical;
|
||||
case FlatpakResource::Extension:
|
||||
@@ -381,12 +381,12 @@ AbstractResource::State FlatpakResource::state()
|
||||
|
||||
FlatpakResource::ResourceType FlatpakResource::resourceType() const
|
||||
{
|
||||
- return m_id.type;
|
||||
+ return m_type;
|
||||
}
|
||||
|
||||
QString FlatpakResource::typeAsString() const
|
||||
{
|
||||
- switch (m_id.type) {
|
||||
+ switch (m_type) {
|
||||
case FlatpakResource::Runtime:
|
||||
case FlatpakResource::Extension:
|
||||
return QLatin1String("runtime");
|
||||
@@ -528,7 +528,7 @@ void FlatpakResource::setState(AbstractResource::State state)
|
||||
|
||||
void FlatpakResource::setType(FlatpakResource::ResourceType type)
|
||||
{
|
||||
- m_id.type = type;
|
||||
+ m_type = type;
|
||||
}
|
||||
|
||||
QString FlatpakResource::installationPath() const
|
||||
diff --git a/libdiscover/backends/FlatpakBackend/FlatpakResource.h b/libdiscover/backends/FlatpakBackend/FlatpakResource.h
|
||||
index 7cf0022d7..364857950 100644
|
||||
--- a/libdiscover/backends/FlatpakBackend/FlatpakResource.h
|
||||
+++ b/libdiscover/backends/FlatpakBackend/FlatpakResource.h
|
||||
@@ -55,7 +55,6 @@ public:
|
||||
Q_ENUM(FlatpakFileType)
|
||||
|
||||
struct Id {
|
||||
- FlatpakResource::ResourceType type;
|
||||
const QString id;
|
||||
QString branch;
|
||||
QString arch;
|
||||
@@ -66,8 +65,7 @@ public:
|
||||
bool operator==(const Id &other) const
|
||||
{
|
||||
return &other == this
|
||||
- || (other.type == type //
|
||||
- && other.id == id //
|
||||
+ || (other.id == id //
|
||||
&& other.branch == branch //
|
||||
&& other.arch == arch //
|
||||
);
|
||||
@@ -183,11 +181,12 @@ private:
|
||||
AbstractResource::State m_state;
|
||||
FlatpakInstallation *const m_installation;
|
||||
QString m_origin;
|
||||
+ FlatpakResource::ResourceType m_type = DesktopApp;
|
||||
};
|
||||
|
||||
inline uint qHash(const FlatpakResource::Id &key)
|
||||
{
|
||||
- return qHash(key.type) ^ qHash(key.id) ^ qHash(key.branch) ^ qHash(key.arch);
|
||||
+ return qHash(key.id) ^ qHash(key.branch) ^ qHash(key.arch);
|
||||
}
|
||||
|
||||
#endif // FLATPAKRESOURCE_H
|
||||
--
|
||||
GitLab
|
||||
|
||||
Reference in New Issue
Block a user