dcavalca / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

Blame SOURCES/0003-Accept-double-eq-as-an-operator-in-reldeps-RhBug-1847946.patch

d3fb65
From 227cf617dd6afd7583f1c864c66ba2ca95e3d09d Mon Sep 17 00:00:00 2001
d3fb65
From: Pavla Kratochvilova <pkratoch@redhat.com>
d3fb65
Date: Wed, 24 Jun 2020 08:48:49 +0200
d3fb65
Subject: [PATCH 1/2] Accept '==' as an operator in reldeps (RhBug:1847946)
d3fb65
d3fb65
Although rpm doesn't support this and using '==' can result in an
d3fb65
unexpected behavior, libdnf accepted '==' by mistake for some time and
d3fb65
other tools (namely Ansible Tower) already rely on it.
d3fb65
d3fb65
This brings back the '==' support with a deprecation warning.
d3fb65
d3fb65
https://bugzilla.redhat.com/show_bug.cgi?id=1847946
d3fb65
---
d3fb65
 libdnf/repo/DependencySplitter.cpp | 14 +++++++++++++-
d3fb65
 1 file changed, 13 insertions(+), 1 deletion(-)
d3fb65
d3fb65
diff --git a/libdnf/repo/DependencySplitter.cpp b/libdnf/repo/DependencySplitter.cpp
d3fb65
index 0030ea6d3..402962286 100644
d3fb65
--- a/libdnf/repo/DependencySplitter.cpp
d3fb65
+++ b/libdnf/repo/DependencySplitter.cpp
d3fb65
@@ -20,16 +20,21 @@
d3fb65
 
d3fb65
 #include "DependencySplitter.hpp"
d3fb65
 #include "../dnf-sack.h"
d3fb65
+#include "../log.hpp"
d3fb65
 #include "../utils/regex/regex.hpp"
d3fb65
 
d3fb65
+#include "bgettext/bgettext-lib.h"
d3fb65
+#include "tinyformat/tinyformat.hpp"
d3fb65
+
d3fb65
 namespace libdnf {
d3fb65
 
d3fb65
 static const Regex RELDEP_REGEX = 
d3fb65
-    Regex("^(\\S*)\\s*(<=|>=|<|>|=)?\\s*(\\S*)$", REG_EXTENDED);
d3fb65
+    Regex("^(\\S*)\\s*(<=|>=|<|>|=|==)?\\s*(\\S*)$", REG_EXTENDED);
d3fb65
 
d3fb65
 static bool
d3fb65
 getCmpFlags(int *cmp_type, std::string matchCmpType)
d3fb65
 {
d3fb65
+    auto logger(Log::getLogger());
d3fb65
     int subexpr_len = matchCmpType.size();
d3fb65
     auto match_start = matchCmpType.c_str();
d3fb65
     if (subexpr_len == 2) {
d3fb65
@@ -41,6 +46,13 @@ getCmpFlags(int *cmp_type, std::string matchCmpType)
d3fb65
             *cmp_type |= HY_GT;
d3fb65
             *cmp_type |= HY_EQ;
d3fb65
         }
d3fb65
+        else if (strncmp(match_start, "==", 2) == 0) {
d3fb65
+            auto msg = tfm::format(_("Using '==' operator in reldeps can result in an undefined "
d3fb65
+                                     "behavior. It is deprecated and the support will be dropped "
d3fb65
+                                     "in future versions. Use '=' operator instead."));
d3fb65
+            logger->warning(msg);
d3fb65
+            *cmp_type |= HY_EQ;
d3fb65
+        }
d3fb65
         else
d3fb65
             return false;
d3fb65
     } else if (subexpr_len == 1) {
d3fb65
d3fb65
From 1f9b14f1d30113a602e18f60ef7ba1f11aead10f Mon Sep 17 00:00:00 2001
d3fb65
From: Pavla Kratochvilova <pkratoch@redhat.com>
d3fb65
Date: Wed, 24 Jun 2020 13:08:48 +0200
d3fb65
Subject: [PATCH 2/2] Add tests for '==' operator in reldeps
d3fb65
d3fb65
---
d3fb65
 python/hawkey/tests/tests/test_reldep.py | 5 +++++
d3fb65
 1 file changed, 5 insertions(+)
d3fb65
d3fb65
diff --git a/python/hawkey/tests/tests/test_reldep.py b/python/hawkey/tests/tests/test_reldep.py
d3fb65
index 8b479cfd7..a9f6cae6f 100644
d3fb65
--- a/python/hawkey/tests/tests/test_reldep.py
d3fb65
+++ b/python/hawkey/tests/tests/test_reldep.py
d3fb65
@@ -61,6 +61,11 @@ def test_custom_querying(self):
d3fb65
         reldep = hawkey.Reldep(self.sack, "P-lib = 3-3")
d3fb65
         q = hawkey.Query(self.sack).filter(provides=reldep)
d3fb65
         self.assertLength(q, 1)
d3fb65
+        # '==' operator is deprecated and the support will be dropped in future
d3fb65
+        # versions (see bug 1847946)
d3fb65
+        reldep = hawkey.Reldep(self.sack, "P-lib == 3-3")
d3fb65
+        q = hawkey.Query(self.sack).filter(provides=reldep)
d3fb65
+        self.assertLength(q, 1)
d3fb65
         reldep = hawkey.Reldep(self.sack, "P-lib >= 3")
d3fb65
         q = hawkey.Query(self.sack).filter(provides=reldep)
d3fb65
         self.assertLength(q, 1)