dc67ef22.patch 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. From dc67ef22f47b9e8b46d668b811982f33600f1aae Mon Sep 17 00:00:00 2001
  2. From: Aleix Pol <aleixpol@kde.org>
  3. Date: Wed, 10 Nov 2021 01:55:56 +0100
  4. Subject: [PATCH] flatpak: Do not include the resource type in the
  5. FlatpakResource::Id
  6. Otherwise we couldn't make sure that idForInstalledRef() was coherent
  7. with FlatpakResource::uniqueId().
  8. In the end it's not a problem, it's not like we can have an app and
  9. runtime with the same name.
  10. (cherry picked from commit 614450b3ee9175fb16f068af505fb59ed27e6697)
  11. ---
  12. .../FlatpakBackend/FlatpakBackend.cpp | 25 ++++++++-----------
  13. .../FlatpakBackend/FlatpakResource.cpp | 12 ++++-----
  14. .../backends/FlatpakBackend/FlatpakResource.h | 7 +++---
  15. 3 files changed, 19 insertions(+), 25 deletions(-)
  16. diff --git a/libdiscover-kf6/backends/FlatpakBackend/FlatpakBackend.cpp b/libdiscover-kf6/backends/FlatpakBackend/FlatpakBackend.cpp
  17. index 012817ef9..6727b0227 100644
  18. --- a/libdiscover-kf6/backends/FlatpakBackend/FlatpakBackend.cpp
  19. +++ b/libdiscover-kf6/backends/FlatpakBackend/FlatpakBackend.cpp
  20. @@ -149,8 +149,7 @@ QDebug operator<<(QDebug debug, const FlatpakResource::Id &id)
  21. QDebugStateSaver saver(debug);
  22. debug.nospace() << "FlatpakResource::Id(";
  23. debug.nospace() << "name:" << id.id << ',';
  24. - debug.nospace() << "branch:" << id.branch << ',';
  25. - debug.nospace() << "type:" << id.type;
  26. + debug.nospace() << "branch:" << id.branch;
  27. debug.nospace() << ')';
  28. return debug;
  29. }
  30. @@ -162,7 +161,6 @@ static FlatpakResource::Id idForRefString(const QStringView &ref)
  31. auto parts = ref.split('/');
  32. // app/app.getspace.Space/x86_64/stable
  33. return {
  34. - parts[0] == QLatin1String("app") ? FlatpakResource::DesktopApp : FlatpakResource::Runtime,
  35. parts[1].toString(),
  36. parts[3].toString(),
  37. parts[2].toString(),
  38. @@ -178,7 +176,7 @@ static FlatpakResource::Id idForInstalledRef(FlatpakInstalledRef *ref, const QSt
  39. const QString arch = QString::fromUtf8(flatpak_ref_get_arch(FLATPAK_REF(ref)));
  40. const QString branch = QString::fromUtf8(flatpak_ref_get_branch(FLATPAK_REF(ref)));
  41. - return {appType, appId, branch, arch};
  42. + return {appId, branch, arch};
  43. }
  44. FlatpakBackend::FlatpakBackend(QObject *parent)
  45. @@ -350,25 +348,20 @@ QString refToBundleId(FlatpakRef *ref)
  46. FlatpakResource *FlatpakBackend::getAppForInstalledRef(FlatpakInstallation *installation, FlatpakInstalledRef *ref) const
  47. {
  48. - auto id = idForInstalledRef(ref, {});
  49. - for (const auto &source : m_flatpakSources) {
  50. - auto ret = source->m_resources.value(id);
  51. + const QString origin = QString::fromUtf8(flatpak_installed_ref_get_origin(ref));
  52. + auto source = findSource(installation, origin);
  53. + if (source) {
  54. + auto ret = source->m_resources.value(idForInstalledRef(ref, {}));
  55. if (ret) {
  56. return ret;
  57. }
  58. - }
  59. - auto id2 = idForInstalledRef(ref, QStringLiteral(".desktop"));
  60. - for (const auto &source : m_flatpakSources) {
  61. - auto ret = source->m_resources.value(id2);
  62. + ret = source->m_resources.value(idForInstalledRef(ref, QStringLiteral(".desktop")));
  63. if (ret) {
  64. return ret;
  65. }
  66. }
  67. const QLatin1String name(flatpak_ref_get_name(FLATPAK_REF(ref)));
  68. -
  69. - const QString origin = QString::fromUtf8(flatpak_installed_ref_get_origin(ref));
  70. - auto source = findSource(installation, origin);
  71. const QString pathExports = FlatpakResource::installationPath(installation) + QLatin1String("/exports/");
  72. const QString pathApps = pathExports + QLatin1String("share/applications/");
  73. AppStream::Component cid;
  74. @@ -413,6 +406,8 @@ FlatpakResource *FlatpakBackend::getAppForInstalledRef(FlatpakInstallation *inst
  75. resource->updateFromRef(FLATPAK_REF(ref));
  76. resource->setState(AbstractResource::Installed);
  77. source->addResource(resource);
  78. +
  79. + Q_ASSERT(resource->uniqueId() == idForInstalledRef(ref, {}) || resource->uniqueId() == idForInstalledRef(ref, {".desktop"}));
  80. return resource;
  81. }
  82. @@ -445,7 +440,7 @@ FlatpakResource *FlatpakBackend::getRuntimeForApp(FlatpakResource *resource) con
  83. for (const auto &source : m_flatpakSources) {
  84. for (auto it = source->m_resources.constBegin(), itEnd = source->m_resources.constEnd(); it != itEnd; ++it) {
  85. const auto &id = it.key();
  86. - if (id.type == FlatpakResource::Runtime && id.id == runtimeInfo.at(0) && id.branch == runtimeInfo.at(2)) {
  87. + if ((*it)->resourceType() == FlatpakResource::Runtime && id.id == runtimeInfo.at(0) && id.branch == runtimeInfo.at(2)) {
  88. runtime = *it;
  89. break;
  90. }
  91. diff --git a/libdiscover-kf6/backends/FlatpakBackend/FlatpakResource.cpp b/libdiscover-kf6/backends/FlatpakBackend/FlatpakResource.cpp
  92. index 8f6b25575..7419dcee7 100644
  93. --- a/libdiscover-kf6/backends/FlatpakBackend/FlatpakResource.cpp
  94. +++ b/libdiscover-kf6/backends/FlatpakBackend/FlatpakResource.cpp
  95. @@ -41,7 +41,7 @@ static QString iconCachePath(const AppStream::Icon &icon)
  96. FlatpakResource::FlatpakResource(const AppStream::Component &component, FlatpakInstallation *installation, FlatpakBackend *parent)
  97. : AbstractResource(parent)
  98. , m_appdata(component)
  99. - , m_id({FlatpakResource::DesktopApp, component.id(), QString(), QString()})
  100. + , m_id({component.id(), QString(), QString()})
  101. , m_downloadSize(0)
  102. , m_installedSize(0)
  103. , m_propertyStates({{DownloadSize, NotKnownYet}, {InstalledSize, NotKnownYet}, {RequiredRuntime, NotKnownYet}})
  104. @@ -122,7 +122,7 @@ QString FlatpakResource::branch() const
  105. bool FlatpakResource::canExecute() const
  106. {
  107. - return (m_id.type == DesktopApp && (m_state == AbstractResource::Installed || m_state == AbstractResource::Upgradeable));
  108. + return (m_type == DesktopApp && (m_state == AbstractResource::Installed || m_state == AbstractResource::Upgradeable));
  109. }
  110. void FlatpakResource::updateFromRef(FlatpakRef *ref)
  111. @@ -241,7 +241,7 @@ int FlatpakResource::installedSize() const
  112. AbstractResource::Type FlatpakResource::type() const
  113. {
  114. - switch (m_id.type) {
  115. + switch (m_type) {
  116. case FlatpakResource::Runtime:
  117. return Technical;
  118. case FlatpakResource::Extension:
  119. @@ -381,12 +381,12 @@ AbstractResource::State FlatpakResource::state()
  120. FlatpakResource::ResourceType FlatpakResource::resourceType() const
  121. {
  122. - return m_id.type;
  123. + return m_type;
  124. }
  125. QString FlatpakResource::typeAsString() const
  126. {
  127. - switch (m_id.type) {
  128. + switch (m_type) {
  129. case FlatpakResource::Runtime:
  130. case FlatpakResource::Extension:
  131. return QLatin1String("runtime");
  132. @@ -528,7 +528,7 @@ void FlatpakResource::setState(AbstractResource::State state)
  133. void FlatpakResource::setType(FlatpakResource::ResourceType type)
  134. {
  135. - m_id.type = type;
  136. + m_type = type;
  137. }
  138. QString FlatpakResource::installationPath() const
  139. diff --git a/libdiscover-kf6/backends/FlatpakBackend/FlatpakResource.h b/libdiscover-kf6/backends/FlatpakBackend/FlatpakResource.h
  140. index 7cf0022d7..364857950 100644
  141. --- a/libdiscover-kf6/backends/FlatpakBackend/FlatpakResource.h
  142. +++ b/libdiscover-kf6/backends/FlatpakBackend/FlatpakResource.h
  143. @@ -55,7 +55,6 @@ public:
  144. Q_ENUM(FlatpakFileType)
  145. struct Id {
  146. - FlatpakResource::ResourceType type;
  147. const QString id;
  148. QString branch;
  149. QString arch;
  150. @@ -66,8 +65,7 @@ public:
  151. bool operator==(const Id &other) const
  152. {
  153. return &other == this
  154. - || (other.type == type //
  155. - && other.id == id //
  156. + || (other.id == id //
  157. && other.branch == branch //
  158. && other.arch == arch //
  159. );
  160. @@ -183,11 +181,12 @@ private:
  161. AbstractResource::State m_state;
  162. FlatpakInstallation *const m_installation;
  163. QString m_origin;
  164. + FlatpakResource::ResourceType m_type = DesktopApp;
  165. };
  166. inline uint qHash(const FlatpakResource::Id &key)
  167. {
  168. - return qHash(key.type) ^ qHash(key.id) ^ qHash(key.branch) ^ qHash(key.arch);
  169. + return qHash(key.id) ^ qHash(key.branch) ^ qHash(key.arch);
  170. }
  171. #endif // FLATPAKRESOURCE_H
  172. --
  173. GitLab