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