0002-pisi-Enable-comparison-by-release-field-highest-win.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. From 7c3980b2dc488e789b9df8d2fe376bf3c8cd2df7 Mon Sep 17 00:00:00 2001
  2. From: Ikey Doherty <ikey@solus-project.com>
  3. Date: Sun, 26 Jul 2015 17:01:01 +0100
  4. Subject: [PATCH 2/2] pisi: Enable comparison by release field (highest wins)
  5. As of 25 Jun 2021, this patch adapted for appstream-glib 0.7.18 and .pisi format by:
  6. Berk Çakar <berkcakar@pisilinux.org>
  7. Signed-off-by: Ikey Doherty <ikey@solus-project.com>
  8. ---
  9. libappstream-builder/asb-package-pisi.c | 54 ++++++++++++++++++++++++++++++--
  10. 1 file changed, 51 insertions(+), 3 deletions(-)
  11. diff --git a/libappstream-builder/asb-package-pisi.c b/libappstream-builder/asb-package-pisi.c
  12. index cf6572c..4a5bfa6 100644
  13. --- a/libappstream-builder/asb-package-pisi.c
  14. +++ b/libappstream-builder/asb-package-pisi.c
  15. @@ -38,8 +38,6 @@
  16. #include <errno.h>
  17. #include <string.h>
  18. -G_DEFINE_TYPE (AsbPackagePisi, asb_package_pisi, ASB_TYPE_PACKAGE)
  19. -
  20. /**
  21. * Storage for pisi metadata
  22. */
  23. @@ -87,6 +85,17 @@ typedef struct pisi_t {
  24. } pisi_t;
  25. +
  26. +typedef struct _AsbPackagePisiPrivate AsbPackagePisiPrivate;
  27. +struct _AsbPackagePisiPrivate
  28. +{
  29. + pisi_t *package;
  30. +};
  31. +
  32. +G_DEFINE_TYPE_WITH_PRIVATE (AsbPackagePisi, asb_package_pisi, ASB_TYPE_PACKAGE)
  33. +
  34. +#define GET_PRIVATE(o) (asb_package_pisi_get_instance_private (o))
  35. +
  36. /**
  37. * Process metadata.xml node
  38. */
  39. @@ -438,6 +447,19 @@ asb_package_pisi_init (AsbPackagePisi *pkg)
  40. {
  41. }
  42. +/**
  43. + * asb_package_pisi_finalize:
  44. + **/
  45. +static void
  46. +asb_package_pisi_finalize (GObject *object)
  47. +{
  48. + AsbPackagePisi *pkg = ASB_PACKAGE_PISI (object);
  49. + AsbPackagePisiPrivate *priv = GET_PRIVATE (pkg);
  50. +
  51. + close_pisi (priv->package);
  52. +
  53. + G_OBJECT_CLASS (asb_package_pisi_parent_class)->finalize (object);
  54. +}
  55. /**
  56. * asb_package_pisi_open:
  57. @@ -448,11 +470,14 @@ asb_package_pisi_open (AsbPackage *pkg, const gchar *filename, GError **error)
  58. pisi_t *pisi = NULL;
  59. gchar *rel = NULL;
  60. GSList *elem = NULL;
  61. + AsbPackagePisiPrivate *priv = NULL;
  62. pisi = open_pisi(filename);
  63. if (!pisi)
  64. return FALSE;
  65. + priv = GET_PRIVATE(ASB_PACKAGE_PISI(pkg));
  66. +
  67. asb_package_set_name (pkg, pisi->meta->name);
  68. asb_package_set_source (pkg, pisi->meta->source);
  69. @@ -469,7 +494,7 @@ asb_package_pisi_open (AsbPackage *pkg, const gchar *filename, GError **error)
  70. asb_package_set_license (pkg, pisi->meta->licenses->data);
  71. - close_pisi(pisi);
  72. + priv->package = pisi;
  73. return TRUE;
  74. }
  75. @@ -504,14 +529,37 @@ asb_package_pisi_explode (AsbPackage *pkg,
  76. }
  77. /**
  78. + * asb_package_pisi_compare:
  79. + **/
  80. +static gint
  81. +asb_package_pisi_compare (AsbPackage *pkg1, AsbPackage *pkg2)
  82. +{
  83. + AsbPackagePisi *pkg_pisi1 = ASB_PACKAGE_PISI (pkg1);
  84. + AsbPackagePisiPrivate *priv1 = GET_PRIVATE (pkg_pisi1);
  85. +
  86. + AsbPackagePisi *pkg_pisi2 = ASB_PACKAGE_PISI (pkg2);
  87. + AsbPackagePisiPrivate *priv2 = GET_PRIVATE (pkg_pisi2);
  88. +
  89. + gint rel1 = priv1->package->meta->release;
  90. + gint rel2 = priv2->package->meta->release;
  91. +
  92. + return (rel1 > rel2) - (rel1 < rel2);
  93. +}
  94. +
  95. +/**
  96. * asb_package_pisi_class_init:
  97. **/
  98. static void
  99. asb_package_pisi_class_init (AsbPackagePisiClass *klass)
  100. {
  101. AsbPackageClass *package_class = ASB_PACKAGE_CLASS (klass);
  102. + GObjectClass *object_class = G_OBJECT_CLASS (klass);
  103. +
  104. + object_class->finalize = asb_package_pisi_finalize;
  105. +
  106. package_class->open = asb_package_pisi_open;
  107. package_class->explode = asb_package_pisi_explode;
  108. + package_class->compare = asb_package_pisi_compare;
  109. }
  110. /**
  111. --
  112. 2.11.0