chantra / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone
Blob Blame History Raw
From 12acb4b30c9a88b9082f7dcbda0257b47bed9c87 Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Sat, 13 Apr 2019 18:46:28 +0200
Subject: [PATCH 1/3] Add HY_PKG_CONFLICTS for conversion into reldep

Sequence of HY_PKG_CONFLICTS requires conversion into reldep.
---
 python/hawkey/query-py.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/python/hawkey/query-py.cpp b/python/hawkey/query-py.cpp
index d90f9c95..5bc8d123 100644
--- a/python/hawkey/query-py.cpp
+++ b/python/hawkey/query-py.cpp
@@ -350,6 +350,7 @@ filter_add(HyQuery query, key_t keyname, int cmp_type, PyObject *match)
 
         break;
     }
+    case HY_PKG_CONFLICTS:
     case HY_PKG_PROVIDES:
     case HY_PKG_REQUIRES:
     case HY_PKG_ENHANCES:
-- 
2.21.0


From db4118aeab5d8ed0006d7fe8b924304c7f52d34d Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Sat, 13 Apr 2019 19:38:29 +0200
Subject: [PATCH 2/3] Add support of PY string sequence for HY_PKG_OBSOLETES

---
 python/hawkey/query-py.cpp | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/python/hawkey/query-py.cpp b/python/hawkey/query-py.cpp
index 5bc8d123..e9d220b6 100644
--- a/python/hawkey/query-py.cpp
+++ b/python/hawkey/query-py.cpp
@@ -340,10 +340,26 @@ filter_add(HyQuery query, key_t keyname, int cmp_type, PyObject *match)
     switch (keyname) {
     case HY_PKG:
     case HY_PKG_OBSOLETES: {
+        // It could be a sequence of packages or reldep/strings. Lets try packages first.
         auto pset = pyseq_to_packageset(match, query->getSack());
-
-        if (!pset)
+        if (!pset) {
+            if (auto PyError = PyErr_Occurred()) {
+                // It was not a sequence of packages.
+                if (PyErr_GivenExceptionMatches(PyError, PyExc_TypeError)) {
+                    PyErr_Clear();
+                    auto reldeplist = pyseq_to_reldeplist(match, query->getSack(), cmp_type);
+                    if (reldeplist == NULL)
+                        return 1;
+
+                    int ret = query->addFilter(keyname, reldeplist.get());
+                    if (ret) {
+                        return raise_bad_filter();
+                    }
+                    break;
+                }
+            }
             return 1;
+        }
         int ret = query->addFilter(keyname, cmp_type, pset.get());
         if (ret)
             return raise_bad_filter();
-- 
2.21.0


From 247f05ef7c3083953e02948ba629cc9ef4184e05 Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Mon, 15 Apr 2019 09:54:12 +0200
Subject: [PATCH 3/3] Add conversion for sequence to reldep in c/c++ interface

This conversion is supported from Python, but was not implemented in
c/c++ code.

When sequence that requires conversion was used, it failed on assertion.
---
 libdnf.spec           |  2 +-
 libdnf/sack/query.cpp | 29 ++++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/libdnf.spec b/libdnf.spec
index d7b3270a..5f0b6529 100644
--- a/libdnf.spec
+++ b/libdnf.spec
@@ -37,7 +37,7 @@
     %{nil}
 
 Name:           libdnf
-Version:        0.35.1
+Version:        0.35.2
 Release:        1%{?dist}
 Summary:        Library providing simplified C and Python API to libsolv
 License:        LGPLv2+
diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
index d5b29a66..949b5ab9 100644
--- a/libdnf/sack/query.cpp
+++ b/libdnf/sack/query.cpp
@@ -882,7 +882,34 @@ Query::addFilter(int keyname, int cmp_type, const char **matches)
     if (!valid_filter_str(keyname, cmp_type))
         return DNF_ERROR_BAD_QUERY;
     pImpl->applied = false;
-    pImpl->filters.push_back(Filter(keyname, cmp_type, matches));
+    switch (keyname) {
+        case HY_PKG_CONFLICTS:
+        case HY_PKG_ENHANCES:
+        case HY_PKG_OBSOLETES:
+        case HY_PKG_PROVIDES:
+        case HY_PKG_RECOMMENDS:
+        case HY_PKG_REQUIRES:
+        case HY_PKG_SUGGESTS:
+        case HY_PKG_SUPPLEMENTS: {
+            DnfSack *sack = pImpl->sack;
+            const unsigned nmatches = g_strv_length((gchar**)matches);
+            DependencyContainer reldeplist(sack);
+            if (cmp_type == HY_GLOB) {
+                for (unsigned int i = 0; i < nmatches; ++i) {
+                    reldeplist.addReldepWithGlob(matches[i]);
+                }
+            } else {
+                for (unsigned int i = 0; i < nmatches; ++i) {
+                    reldeplist.addReldep(matches[i]);
+                }
+            }
+            return addFilter(keyname, &reldeplist);
+        }
+        default: {
+            pImpl->filters.push_back(Filter(keyname, cmp_type, matches));
+            return 0;
+        }
+    }
     return 0;
 }
 
-- 
2.21.0