Blame SOURCES/0004-Add-testing-if-advisory-is-applicable-for-query-and-package.patch

844bdb
From 4a7556fb53b49ed7e03323913af87998bd48b2b1 Mon Sep 17 00:00:00 2001
844bdb
From: Jaroslav Mracek <jmracek@redhat.com>
844bdb
Date: Tue, 5 Feb 2019 08:58:11 +0100
844bdb
Subject: [PATCH] Add testing if advisory is applicable for query and package
844bdb
844bdb
---
844bdb
 libdnf/hy-package.cpp  |  5 ++++-
844bdb
 libdnf/sack/query.cpp  | 16 +++++++++++-----
844bdb
 libdnf/utils/utils.cpp | 28 ++++++++++++++++++++++++++++
844bdb
 libdnf/utils/utils.hpp |  5 +++++
844bdb
 4 files changed, 48 insertions(+), 6 deletions(-)
844bdb
844bdb
diff --git a/libdnf/hy-package.cpp b/libdnf/hy-package.cpp
844bdb
index 833e082..62f4bb6 100644
844bdb
--- a/libdnf/hy-package.cpp
844bdb
+++ b/libdnf/hy-package.cpp
844bdb
@@ -29,6 +29,7 @@
844bdb
  * See also: #DnfContext
844bdb
  */
844bdb
 
844bdb
+#include "libdnf/utils/utils.hpp"
844bdb
 
844bdb
 #include <algorithm>
844bdb
 #include <ctime>
844bdb
@@ -1015,7 +1016,9 @@ dnf_package_get_advisories(DnfPackage *pkg, int cmp_type)
844bdb
             (cmp < 0 && (cmp_type & HY_LT)) ||
844bdb
             (cmp == 0 && (cmp_type & HY_EQ))) {
844bdb
             advisory = dnf_advisory_new(sack, di.solvid);
844bdb
-            g_ptr_array_add(advisorylist, advisory);
844bdb
+            if (libdnf::isAdvisoryApplicable(*advisory, sack)) {
844bdb
+                g_ptr_array_add(advisorylist, advisory);
844bdb
+            }
844bdb
             dataiterator_skip_solvable(&di);
844bdb
         }
844bdb
     }
844bdb
diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
844bdb
index f1e1076..b3029e2 100644
844bdb
--- a/libdnf/sack/query.cpp
844bdb
+++ b/libdnf/sack/query.cpp
844bdb
@@ -18,6 +18,8 @@
844bdb
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
844bdb
  */
844bdb
 
844bdb
+#include "libdnf/utils/utils.hpp"
844bdb
+
844bdb
 #include <algorithm>
844bdb
 #include <assert.h>
844bdb
 #include <fnmatch.h>
844bdb
@@ -1518,7 +1520,9 @@ Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
844bdb
                     eq = false;
844bdb
             }
844bdb
             if (eq) {
844bdb
-                advisory.getPackages(pkgs, false);
844bdb
+                if (isAdvisoryApplicable(advisory, sack)) {
844bdb
+                    advisory.getPackages(pkgs, false);
844bdb
+                }
844bdb
                 break;
844bdb
             }
844bdb
         }
844bdb
@@ -2049,18 +2053,20 @@ void
844bdb
 Query::getAdvisoryPkgs(int cmpType, std::vector<AdvisoryPkg> & advisoryPkgs)
844bdb
 {
844bdb
     apply();
844bdb
-    Pool *pool = dnf_sack_get_pool(pImpl->sack);
844bdb
+    auto sack = pImpl->sack;
844bdb
+    Pool *pool = dnf_sack_get_pool(sack);
844bdb
     std::vector<AdvisoryPkg> pkgs;
844bdb
     Dataiterator di;
844bdb
     auto resultPset = pImpl->result.get();
844bdb
 
844bdb
     // iterate over advisories
844bdb
     dataiterator_init(&di, pool, 0, 0, 0, 0, 0);
844bdb
     dataiterator_prepend_keyname(&di, UPDATE_COLLECTION);
844bdb
     while (dataiterator_step(&di)) {
844bdb
-        Advisory advisory(pImpl->sack, di.solvid);
844bdb
-
844bdb
-        advisory.getPackages(pkgs);
844bdb
+        Advisory advisory(sack, di.solvid);
844bdb
+        if (isAdvisoryApplicable(advisory, sack)) {
844bdb
+            advisory.getPackages(pkgs);
844bdb
+        }
844bdb
         dataiterator_skip_solvable(&di);
844bdb
     }
844bdb
     dataiterator_free(&di);
844bdb
diff --git a/libdnf/utils/utils.cpp b/libdnf/utils/utils.cpp
844bdb
index a1ffb49..3833614 100644
844bdb
--- a/libdnf/utils/utils.cpp
844bdb
+++ b/libdnf/utils/utils.cpp
844bdb
@@ -1,4 +1,6 @@
844bdb
 #include "utils.hpp"
844bdb
+#include "libdnf/dnf-sack-private.hpp"
844bdb
+#include "libdnf/sack/advisorymodule.hpp"
844bdb
 
844bdb
 #include <algorithm>
844bdb
 #include <sys/stat.h>
844bdb
@@ -10,6 +12,32 @@
844bdb
 #include <unistd.h>
844bdb
 #include <string.h>
844bdb
 
844bdb
+bool libdnf::isAdvisoryApplicable(libdnf::Advisory & advisory, DnfSack * sack)
844bdb
+{
844bdb
+    auto moduleContainer = dnf_sack_get_module_container(sack);
844bdb
+    if (!moduleContainer) {
844bdb
+        return true;
844bdb
+    }
844bdb
+    auto moduleAdvisories = advisory.getModules();
844bdb
+    if (moduleAdvisories.empty()) {
844bdb
+        return true;
844bdb
+    }
844bdb
+    for (auto & moduleAdvisory: moduleAdvisories) {
844bdb
+        if (const char * name = moduleAdvisory.getName()) {
844bdb
+            if (const char * stream = moduleAdvisory.getStream()) {
844bdb
+                try {
844bdb
+                    if (moduleContainer->isEnabled(name, stream)) {
844bdb
+                        return true;
844bdb
+                    }
844bdb
+                } catch (std::out_of_range) {
844bdb
+                    continue;
844bdb
+                }
844bdb
+            }
844bdb
+        }
844bdb
+    }
844bdb
+    return false;
844bdb
+}
844bdb
+
844bdb
 std::vector<std::string> libdnf::string::split(const std::string &source, const char *delimiter, int maxSplit)
844bdb
 {
844bdb
     if (source.empty())
844bdb
diff --git a/libdnf/utils/utils.hpp b/libdnf/utils/utils.hpp
844bdb
index aaab5b0..519339f 100644
844bdb
--- a/libdnf/utils/utils.hpp
844bdb
+++ b/libdnf/utils/utils.hpp
844bdb
@@ -1,6 +1,8 @@
844bdb
 #ifndef LIBDNF_UTILS_HPP
844bdb
 #define LIBDNF_UTILS_HPP
844bdb
 
844bdb
+#include "libdnf/sack/advisory.hpp"
844bdb
+
844bdb
 #include <functional>
844bdb
 #include <string>
844bdb
 #include <vector>
844bdb
@@ -25,6 +27,9 @@ private:
844bdb
 };
844bdb
 
844bdb
 namespace libdnf {
844bdb
+
844bdb
+bool isAdvisoryApplicable(Advisory & advisory, DnfSack * sack);
844bdb
+
844bdb
 namespace string {
844bdb
 inline std::string fromCstring(const char * cstring) { return cstring ? cstring : ""; }
844bdb
 std::vector<std::string> split(const std::string &source, const char *delimiter, int maxSplit = -1);
844bdb
--
844bdb
libgit2 0.27.7
844bdb