richardphibel / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

Blame SOURCES/0008-Add-suport-for-query-sequence-conversions.patch

885e9e
From 12acb4b30c9a88b9082f7dcbda0257b47bed9c87 Mon Sep 17 00:00:00 2001
885e9e
From: Jaroslav Mracek <jmracek@redhat.com>
885e9e
Date: Sat, 13 Apr 2019 18:46:28 +0200
885e9e
Subject: [PATCH 1/3] Add HY_PKG_CONFLICTS for conversion into reldep
885e9e
885e9e
Sequence of HY_PKG_CONFLICTS requires conversion into reldep.
885e9e
---
885e9e
 python/hawkey/query-py.cpp | 1 +
885e9e
 1 file changed, 1 insertion(+)
885e9e
885e9e
diff --git a/python/hawkey/query-py.cpp b/python/hawkey/query-py.cpp
885e9e
index d90f9c95..5bc8d123 100644
885e9e
--- a/python/hawkey/query-py.cpp
885e9e
+++ b/python/hawkey/query-py.cpp
885e9e
@@ -350,6 +350,7 @@ filter_add(HyQuery query, key_t keyname, int cmp_type, PyObject *match)
885e9e
 
885e9e
         break;
885e9e
     }
885e9e
+    case HY_PKG_CONFLICTS:
885e9e
     case HY_PKG_PROVIDES:
885e9e
     case HY_PKG_REQUIRES:
885e9e
     case HY_PKG_ENHANCES:
885e9e
-- 
885e9e
2.21.0
885e9e
885e9e
885e9e
From db4118aeab5d8ed0006d7fe8b924304c7f52d34d Mon Sep 17 00:00:00 2001
885e9e
From: Jaroslav Mracek <jmracek@redhat.com>
885e9e
Date: Sat, 13 Apr 2019 19:38:29 +0200
885e9e
Subject: [PATCH 2/3] Add support of PY string sequence for HY_PKG_OBSOLETES
885e9e
885e9e
---
885e9e
 python/hawkey/query-py.cpp | 20 ++++++++++++++++++--
885e9e
 1 file changed, 18 insertions(+), 2 deletions(-)
885e9e
885e9e
diff --git a/python/hawkey/query-py.cpp b/python/hawkey/query-py.cpp
885e9e
index 5bc8d123..e9d220b6 100644
885e9e
--- a/python/hawkey/query-py.cpp
885e9e
+++ b/python/hawkey/query-py.cpp
885e9e
@@ -340,10 +340,26 @@ filter_add(HyQuery query, key_t keyname, int cmp_type, PyObject *match)
885e9e
     switch (keyname) {
885e9e
     case HY_PKG:
885e9e
     case HY_PKG_OBSOLETES: {
885e9e
+        // It could be a sequence of packages or reldep/strings. Lets try packages first.
885e9e
         auto pset = pyseq_to_packageset(match, query->getSack());
885e9e
-
885e9e
-        if (!pset)
885e9e
+        if (!pset) {
885e9e
+            if (auto PyError = PyErr_Occurred()) {
885e9e
+                // It was not a sequence of packages.
885e9e
+                if (PyErr_GivenExceptionMatches(PyError, PyExc_TypeError)) {
885e9e
+                    PyErr_Clear();
885e9e
+                    auto reldeplist = pyseq_to_reldeplist(match, query->getSack(), cmp_type);
885e9e
+                    if (reldeplist == NULL)
885e9e
+                        return 1;
885e9e
+
885e9e
+                    int ret = query->addFilter(keyname, reldeplist.get());
885e9e
+                    if (ret) {
885e9e
+                        return raise_bad_filter();
885e9e
+                    }
885e9e
+                    break;
885e9e
+                }
885e9e
+            }
885e9e
             return 1;
885e9e
+        }
885e9e
         int ret = query->addFilter(keyname, cmp_type, pset.get());
885e9e
         if (ret)
885e9e
             return raise_bad_filter();
885e9e
-- 
885e9e
2.21.0
885e9e
885e9e
885e9e
From 247f05ef7c3083953e02948ba629cc9ef4184e05 Mon Sep 17 00:00:00 2001
885e9e
From: Jaroslav Mracek <jmracek@redhat.com>
885e9e
Date: Mon, 15 Apr 2019 09:54:12 +0200
885e9e
Subject: [PATCH 3/3] Add conversion for sequence to reldep in c/c++ interface
885e9e
885e9e
This conversion is supported from Python, but was not implemented in
885e9e
c/c++ code.
885e9e
885e9e
When sequence that requires conversion was used, it failed on assertion.
885e9e
---
885e9e
 libdnf.spec           |  2 +-
885e9e
 libdnf/sack/query.cpp | 29 ++++++++++++++++++++++++++++-
885e9e
 2 files changed, 29 insertions(+), 2 deletions(-)
885e9e
885e9e
diff --git a/libdnf.spec b/libdnf.spec
885e9e
index d7b3270a..5f0b6529 100644
885e9e
--- a/libdnf.spec
885e9e
+++ b/libdnf.spec
885e9e
@@ -37,7 +37,7 @@
885e9e
     %{nil}
885e9e
 
885e9e
 Name:           libdnf
885e9e
-Version:        0.35.1
885e9e
+Version:        0.35.2
885e9e
 Release:        1%{?dist}
885e9e
 Summary:        Library providing simplified C and Python API to libsolv
885e9e
 License:        LGPLv2+
885e9e
diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
885e9e
index d5b29a66..949b5ab9 100644
885e9e
--- a/libdnf/sack/query.cpp
885e9e
+++ b/libdnf/sack/query.cpp
885e9e
@@ -882,7 +882,34 @@ Query::addFilter(int keyname, int cmp_type, const char **matches)
885e9e
     if (!valid_filter_str(keyname, cmp_type))
885e9e
         return DNF_ERROR_BAD_QUERY;
885e9e
     pImpl->applied = false;
885e9e
-    pImpl->filters.push_back(Filter(keyname, cmp_type, matches));
885e9e
+    switch (keyname) {
885e9e
+        case HY_PKG_CONFLICTS:
885e9e
+        case HY_PKG_ENHANCES:
885e9e
+        case HY_PKG_OBSOLETES:
885e9e
+        case HY_PKG_PROVIDES:
885e9e
+        case HY_PKG_RECOMMENDS:
885e9e
+        case HY_PKG_REQUIRES:
885e9e
+        case HY_PKG_SUGGESTS:
885e9e
+        case HY_PKG_SUPPLEMENTS: {
885e9e
+            DnfSack *sack = pImpl->sack;
885e9e
+            const unsigned nmatches = g_strv_length((gchar**)matches);
885e9e
+            DependencyContainer reldeplist(sack);
885e9e
+            if (cmp_type == HY_GLOB) {
885e9e
+                for (unsigned int i = 0; i < nmatches; ++i) {
885e9e
+                    reldeplist.addReldepWithGlob(matches[i]);
885e9e
+                }
885e9e
+            } else {
885e9e
+                for (unsigned int i = 0; i < nmatches; ++i) {
885e9e
+                    reldeplist.addReldep(matches[i]);
885e9e
+                }
885e9e
+            }
885e9e
+            return addFilter(keyname, &reldeplist);
885e9e
+        }
885e9e
+        default: {
885e9e
+            pImpl->filters.push_back(Filter(keyname, cmp_type, matches));
885e9e
+            return 0;
885e9e
+        }
885e9e
+    }
885e9e
     return 0;
885e9e
 }
885e9e
 
885e9e
-- 
885e9e
2.21.0
885e9e