From 27112644c0e17510fa8e07ba4949b9fbd89655bc Mon Sep 17 00:00:00 2001 From: Jaroslav Mracek Date: Thu, 17 Jan 2019 16:04:48 +0100 Subject: [PATCH] Add support for Module advisories --- libdnf/sack/CMakeLists.txt | 1 + libdnf/sack/advisory.cpp | 21 +++++++++++++++++++++ libdnf/sack/advisory.hpp | 2 ++ libdnf/sack/advisorymodule.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ libdnf/sack/advisorymodule.hpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 195 insertions(+) create mode 100644 libdnf/sack/advisorymodule.cpp create mode 100644 libdnf/sack/advisorymodule.hpp diff --git a/libdnf/sack/CMakeLists.txt b/libdnf/sack/CMakeLists.txt index e1c6be1..9921c74 100644 --- a/libdnf/sack/CMakeLists.txt +++ b/libdnf/sack/CMakeLists.txt @@ -1,6 +1,7 @@ SET (SACK_SOURCES ${SACK_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/advisory.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/advisorymodule.cpp ${CMAKE_CURRENT_SOURCE_DIR}/advisorypkg.cpp ${CMAKE_CURRENT_SOURCE_DIR}/advisoryref.cpp ${CMAKE_CURRENT_SOURCE_DIR}/packageset.cpp diff --git a/libdnf/sack/advisory.cpp b/libdnf/sack/advisory.cpp index d006bcc..bb9e7f4 100644 --- a/libdnf/sack/advisory.cpp +++ b/libdnf/sack/advisory.cpp @@ -24,6 +24,7 @@ #include "advisory.hpp" #include "advisorypkg.hpp" +#include "advisorymodule.hpp" #include "advisoryref.hpp" #include "../dnf-advisory-private.hpp" #include "../dnf-advisoryref.h" @@ -133,6 +134,26 @@ Advisory::getPackages(std::vector & pkglist, bool withFilemanes) co dataiterator_free(&di); } +std::vector Advisory::getModules() const +{ + std::vector moduleList; + Dataiterator di; + Pool *pool = dnf_sack_get_pool(sack); + + dataiterator_init(&di, pool, 0, advisory, UPDATE_MODULE, 0, 0); + while (dataiterator_step(&di)) { + dataiterator_setpos(&di); + Id name = pool_lookup_id(pool, SOLVID_POS, UPDATE_MODULE_NAME); + Id stream = pool_lookup_id(pool, SOLVID_POS, UPDATE_MODULE_STREAM); + Id version = pool_lookup_id(pool, SOLVID_POS, UPDATE_MODULE_VERSION); + Id context = pool_lookup_id(pool, SOLVID_POS, UPDATE_MODULE_CONTEXT); + Id arch = pool_lookup_id(pool, SOLVID_POS, UPDATE_MODULE_ARCH); + moduleList.emplace_back(sack, advisory, name, stream, version, context, arch); + } + dataiterator_free(&di); + return moduleList; +} + void Advisory::getReferences(std::vector & reflist) const { diff --git a/libdnf/sack/advisory.hpp b/libdnf/sack/advisory.hpp index 3771257..5aa8dc6 100644 --- a/libdnf/sack/advisory.hpp +++ b/libdnf/sack/advisory.hpp @@ -33,15 +33,17 @@ namespace libdnf { struct AdvisoryPkg; +struct AdvisoryModule; struct Advisory { public: Advisory(DnfSack *sack, Id advisory); bool operator ==(const Advisory & other) const; const char *getDescription() const; DnfAdvisoryKind getKind() const; const char *getName() const; void getPackages(std::vector & pkglist, bool withFilemanes = true) const; + std::vector getModules() const; void getReferences(std::vector & reflist) const; const char *getRights() const; const char *getSeverity() const; diff --git a/libdnf/sack/advisorymodule.cpp b/libdnf/sack/advisorymodule.cpp new file mode 100644 index 0000000..a209b5f --- /dev/null +++ b/libdnf/sack/advisorymodule.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2019 Red Hat, Inc. + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include + +#include "advisory.hpp" +#include "advisorymodule.hpp" +#include "../dnf-sack-private.hpp" + +namespace libdnf { + +class AdvisoryModule::Impl { +private: + friend AdvisoryModule; + DnfSack *sack; + Id advisory; + Id name; + Id stream; + Id version; + Id context; + Id arch; +}; + +AdvisoryModule::AdvisoryModule(DnfSack *sack, Id advisory, Id name, Id stream, Id version, Id context, Id arch) : pImpl(new Impl) +{ + pImpl->sack = sack; + pImpl->advisory = advisory; + pImpl->name = name; + pImpl->stream = stream; + pImpl->version = version; + pImpl->context = context; + pImpl->arch = arch; +} +AdvisoryModule::AdvisoryModule(const AdvisoryModule & src) : pImpl(new Impl) { *pImpl = *src.pImpl; } +AdvisoryModule::AdvisoryModule(AdvisoryModule && src) : pImpl(new Impl) { pImpl.swap(src.pImpl); } +AdvisoryModule::~AdvisoryModule() = default; + +AdvisoryModule & AdvisoryModule::operator=(const AdvisoryModule & src) { *pImpl = *src.pImpl; return *this; } + +AdvisoryModule & +AdvisoryModule::operator=(AdvisoryModule && src) noexcept +{ + pImpl.swap(src.pImpl); + return *this; +} + +bool +AdvisoryModule::nsvcaEQ(AdvisoryModule & other) +{ + return other.pImpl->name == pImpl->name && + other.pImpl->stream == pImpl->stream && + other.pImpl->version == pImpl->version && + other.pImpl->context == pImpl->context && + other.pImpl->arch == pImpl->arch; +} + +Advisory * AdvisoryModule::getAdvisory() const +{ + return new Advisory(pImpl->sack, pImpl->advisory); +} + +const char * +AdvisoryModule::getName() const +{ + return pool_id2str(dnf_sack_get_pool(pImpl->sack), pImpl->name); +} + +const char * +AdvisoryModule::getStream() const +{ + return pool_id2str(dnf_sack_get_pool(pImpl->sack), pImpl->stream); +} + +const char * +AdvisoryModule::getVersion() const +{ + return pool_id2str(dnf_sack_get_pool(pImpl->sack), pImpl->version); +} + +const char * +AdvisoryModule::getContext() const +{ + return pool_id2str(dnf_sack_get_pool(pImpl->sack), pImpl->context); +} + +const char * +AdvisoryModule::getArch() const +{ + return pool_id2str(dnf_sack_get_pool(pImpl->sack), pImpl->arch); +} + +DnfSack * AdvisoryModule::getSack() { return pImpl->sack; } + +} diff --git a/libdnf/sack/advisorymodule.hpp b/libdnf/sack/advisorymodule.hpp new file mode 100644 index 0000000..1ad1ea7 --- /dev/null +++ b/libdnf/sack/advisorymodule.hpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2019 Red Hat, Inc. + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#ifndef __ADVISORY_MODULE_HPP +#define __ADVISORY_MODULE_HPP + +#include + +#include +#include + +#include "../dnf-types.h" +#include "advisory.hpp" + +namespace libdnf { + +struct AdvisoryModule { +public: + AdvisoryModule(DnfSack *sack, Id advisory, Id name, Id stream, Id version, Id context, Id arch); + AdvisoryModule(const AdvisoryModule & src); + AdvisoryModule(AdvisoryModule && src); + ~AdvisoryModule(); + AdvisoryModule & operator=(const AdvisoryModule & src); + AdvisoryModule & operator=(AdvisoryModule && src) noexcept; + bool nsvcaEQ(AdvisoryModule & other); + Advisory * getAdvisory() const; + const char * getName() const; + const char * getStream() const; + const char * getVersion() const; + const char * getContext() const; + const char * getArch() const; + DnfSack * getSack(); +private: + class Impl; + std::unique_ptr pImpl; +}; + +} + +#endif /* __ADVISORY_MODULE_HPP */ -- libgit2 0.27.7