1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
// Copyright Contributors to the DNF5 project.
// Copyright Contributors to the libdnf project.
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
//
// Libdnf 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.
//
// Libdnf 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 libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "libdnf5/advisory/advisory_collection.hpp"
#include "advisory/advisory_module_private.hpp"
#include "advisory/advisory_package_private.hpp"
namespace libdnf5::advisory {
class AdvisoryCollection::Impl {
public:
explicit Impl(const libdnf5::BaseWeakPtr & base, AdvisoryId advisory, int index)
: advisory(advisory),
index(index),
base(base) {}
/// Get all AdvisoryModules stored in this AdvisoryCollection
/// @param output std::vector of AdvisorModules used as output.
/// This is much faster than returning new std::vector and later joining
/// them when collecting AdvisoryModules from multiple collections.
void get_modules(std::vector<AdvisoryModule> & output);
private:
friend AdvisoryCollection;
AdvisoryId advisory;
/// AdvisoryCollections don't have their own Id, therefore store it's index in its Advisory (just like AdvisoryReference)
int index;
BaseWeakPtr base;
};
AdvisoryCollection::AdvisoryCollection(const libdnf5::BaseWeakPtr & base, AdvisoryId advisory, int index)
: p_impl(std::make_unique<Impl>(base, advisory, index)) {}
AdvisoryCollection::~AdvisoryCollection() = default;
AdvisoryCollection::AdvisoryCollection(const AdvisoryCollection & src) : p_impl(new Impl(*src.p_impl)) {}
AdvisoryCollection & AdvisoryCollection::operator=(const AdvisoryCollection & src) {
if (this != &src) {
if (p_impl) {
*p_impl = *src.p_impl;
} else {
p_impl = std::make_unique<Impl>(*src.p_impl);
}
}
return *this;
}
AdvisoryCollection::AdvisoryCollection(AdvisoryCollection && src) noexcept = default;
AdvisoryCollection & AdvisoryCollection::operator=(AdvisoryCollection && src) noexcept = default;
bool AdvisoryCollection::is_applicable() const {
//TODO(amatej): check if collection is applicable
return true;
}
std::vector<AdvisoryPackage> AdvisoryCollection::get_packages() {
std::vector<AdvisoryPackage> output;
get_packages(output, true);
return output;
}
std::vector<AdvisoryModule> AdvisoryCollection::get_modules() {
std::vector<AdvisoryModule> output;
p_impl->get_modules(output);
return output;
}
void AdvisoryCollection::get_packages(std::vector<AdvisoryPackage> & output, bool with_filemanes) {
Dataiterator di;
const char * filename = nullptr;
auto & pool = get_rpm_pool(p_impl->base);
int count = 0;
dataiterator_init(&di, *pool, 0, p_impl->advisory.id, UPDATE_COLLECTIONLIST, 0, 0);
while (dataiterator_step(&di)) {
dataiterator_setpos(&di);
if (count == p_impl->index) {
Dataiterator di_inner;
dataiterator_init(&di_inner, *pool, 0, SOLVID_POS, UPDATE_COLLECTION, 0, 0);
while (dataiterator_step(&di_inner)) {
dataiterator_setpos(&di_inner);
Id name = pool.lookup_id(SOLVID_POS, UPDATE_COLLECTION_NAME);
Id evr = pool.lookup_id(SOLVID_POS, UPDATE_COLLECTION_EVR);
Id arch = pool.lookup_id(SOLVID_POS, UPDATE_COLLECTION_ARCH);
bool reboot_suggested = pool.lookup_void(SOLVID_POS, UPDATE_REBOOT);
bool restart_suggested = pool.lookup_void(SOLVID_POS, UPDATE_RESTART);
bool relogin_suggested = pool.lookup_void(SOLVID_POS, UPDATE_RELOGIN);
if (with_filemanes) {
filename = pool.lookup_str(SOLVID_POS, UPDATE_COLLECTION_FILENAME);
}
output.emplace_back(AdvisoryPackage(new AdvisoryPackage::Impl(
p_impl->base,
p_impl->advisory,
p_impl->index,
name,
evr,
arch,
reboot_suggested,
restart_suggested,
relogin_suggested,
filename)));
}
dataiterator_free(&di_inner);
break;
}
count++;
}
dataiterator_free(&di);
}
void AdvisoryCollection::Impl::get_modules(std::vector<AdvisoryModule> & output) {
Dataiterator di;
auto & pool = get_rpm_pool(base);
int count = 0;
dataiterator_init(&di, *pool, 0, advisory.id, UPDATE_COLLECTIONLIST, 0, 0);
while (dataiterator_step(&di)) {
dataiterator_setpos(&di);
if (count == index) {
Dataiterator di_inner;
dataiterator_init(&di_inner, *pool, 0, SOLVID_POS, UPDATE_MODULE, 0, 0);
while (dataiterator_step(&di_inner)) {
dataiterator_setpos(&di_inner);
Id name = pool.lookup_id(SOLVID_POS, UPDATE_MODULE_NAME);
Id stream = pool.lookup_id(SOLVID_POS, UPDATE_MODULE_STREAM);
Id version = pool.lookup_id(SOLVID_POS, UPDATE_MODULE_VERSION);
Id context = pool.lookup_id(SOLVID_POS, UPDATE_MODULE_CONTEXT);
Id arch = pool.lookup_id(SOLVID_POS, UPDATE_MODULE_ARCH);
output.emplace_back(AdvisoryModule(
new AdvisoryModule::Impl(base, advisory, index, name, stream, version, context, arch)));
}
dataiterator_free(&di_inner);
break;
}
count++;
}
dataiterator_free(&di);
}
AdvisoryId AdvisoryCollection::get_advisory_id() const {
return p_impl->advisory;
}
Advisory AdvisoryCollection::get_advisory() const {
return Advisory(p_impl->base, p_impl->advisory);
}
} // namespace libdnf5::advisory
|