dcavalca / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone
Blob Blame History Raw
From 227cf617dd6afd7583f1c864c66ba2ca95e3d09d Mon Sep 17 00:00:00 2001
From: Pavla Kratochvilova <pkratoch@redhat.com>
Date: Wed, 24 Jun 2020 08:48:49 +0200
Subject: [PATCH 1/2] Accept '==' as an operator in reldeps (RhBug:1847946)

Although rpm doesn't support this and using '==' can result in an
unexpected behavior, libdnf accepted '==' by mistake for some time and
other tools (namely Ansible Tower) already rely on it.

This brings back the '==' support with a deprecation warning.

https://bugzilla.redhat.com/show_bug.cgi?id=1847946
---
 libdnf/repo/DependencySplitter.cpp | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/libdnf/repo/DependencySplitter.cpp b/libdnf/repo/DependencySplitter.cpp
index 0030ea6d3..402962286 100644
--- a/libdnf/repo/DependencySplitter.cpp
+++ b/libdnf/repo/DependencySplitter.cpp
@@ -20,16 +20,21 @@
 
 #include "DependencySplitter.hpp"
 #include "../dnf-sack.h"
+#include "../log.hpp"
 #include "../utils/regex/regex.hpp"
 
+#include "bgettext/bgettext-lib.h"
+#include "tinyformat/tinyformat.hpp"
+
 namespace libdnf {
 
 static const Regex RELDEP_REGEX = 
-    Regex("^(\\S*)\\s*(<=|>=|<|>|=)?\\s*(\\S*)$", REG_EXTENDED);
+    Regex("^(\\S*)\\s*(<=|>=|<|>|=|==)?\\s*(\\S*)$", REG_EXTENDED);
 
 static bool
 getCmpFlags(int *cmp_type, std::string matchCmpType)
 {
+    auto logger(Log::getLogger());
     int subexpr_len = matchCmpType.size();
     auto match_start = matchCmpType.c_str();
     if (subexpr_len == 2) {
@@ -41,6 +46,13 @@ getCmpFlags(int *cmp_type, std::string matchCmpType)
             *cmp_type |= HY_GT;
             *cmp_type |= HY_EQ;
         }
+        else if (strncmp(match_start, "==", 2) == 0) {
+            auto msg = tfm::format(_("Using '==' operator in reldeps can result in an undefined "
+                                     "behavior. It is deprecated and the support will be dropped "
+                                     "in future versions. Use '=' operator instead."));
+            logger->warning(msg);
+            *cmp_type |= HY_EQ;
+        }
         else
             return false;
     } else if (subexpr_len == 1) {

From 1f9b14f1d30113a602e18f60ef7ba1f11aead10f Mon Sep 17 00:00:00 2001
From: Pavla Kratochvilova <pkratoch@redhat.com>
Date: Wed, 24 Jun 2020 13:08:48 +0200
Subject: [PATCH 2/2] Add tests for '==' operator in reldeps

---
 python/hawkey/tests/tests/test_reldep.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/python/hawkey/tests/tests/test_reldep.py b/python/hawkey/tests/tests/test_reldep.py
index 8b479cfd7..a9f6cae6f 100644
--- a/python/hawkey/tests/tests/test_reldep.py
+++ b/python/hawkey/tests/tests/test_reldep.py
@@ -61,6 +61,11 @@ def test_custom_querying(self):
         reldep = hawkey.Reldep(self.sack, "P-lib = 3-3")
         q = hawkey.Query(self.sack).filter(provides=reldep)
         self.assertLength(q, 1)
+        # '==' operator is deprecated and the support will be dropped in future
+        # versions (see bug 1847946)
+        reldep = hawkey.Reldep(self.sack, "P-lib == 3-3")
+        q = hawkey.Query(self.sack).filter(provides=reldep)
+        self.assertLength(q, 1)
         reldep = hawkey.Reldep(self.sack, "P-lib >= 3")
         q = hawkey.Query(self.sack).filter(provides=reldep)
         self.assertLength(q, 1)