File: advisory_package.cpp

package info (click to toggle)
dnf5 5.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,960 kB
  • sloc: cpp: 94,312; python: 3,370; xml: 1,073; ruby: 600; sql: 250; ansic: 232; sh: 104; perl: 62; makefile: 30
file content (159 lines) | stat: -rw-r--r-- 5,179 bytes parent folder | download
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
// 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_package.hpp"

#include "advisory_package_private.hpp"
#include "rpm/package_set_impl.hpp"

#include <solv/chksum.h>
#include <solv/repo.h>
#include <solv/util.h>


namespace libdnf5::advisory {

// AdvisoryPackage
AdvisoryPackage::AdvisoryPackage(AdvisoryPackage::Impl * private_pkg) : p_impl(private_pkg) {}

AdvisoryPackage::AdvisoryPackage(const AdvisoryPackage & src) = default;
AdvisoryPackage::AdvisoryPackage(AdvisoryPackage && src) noexcept = default;
AdvisoryPackage & AdvisoryPackage::operator=(const AdvisoryPackage & src) = default;
AdvisoryPackage & AdvisoryPackage::operator=(AdvisoryPackage && src) noexcept = default;
AdvisoryPackage::~AdvisoryPackage() = default;


std::string AdvisoryPackage::get_name() const {
    return p_impl->get_name();
}

std::string AdvisoryPackage::get_epoch() const {
    return p_impl->get_epoch();
}

std::string AdvisoryPackage::get_version() const {
    return p_impl->get_version();
}

std::string AdvisoryPackage::get_release() const {
    return p_impl->get_release();
}

std::string AdvisoryPackage::get_evr() const {
    return p_impl->get_evr();
}
std::string AdvisoryPackage::get_arch() const {
    return p_impl->get_arch();
}
std::string AdvisoryPackage::get_nevra() const {
    return p_impl->get_name() + "-" + p_impl->get_evr() + "." + p_impl->get_arch();
}
AdvisoryId AdvisoryPackage::get_advisory_id() const {
    return p_impl->get_advisory_id();
}
Advisory AdvisoryPackage::get_advisory() const {
    return Advisory(p_impl->base, p_impl->get_advisory_id());
}
AdvisoryCollection AdvisoryPackage::get_advisory_collection() const {
    return AdvisoryCollection(p_impl->base, p_impl->get_advisory_id(), p_impl->owner_collection_index);
}
bool AdvisoryPackage::get_reboot_suggested() const {
    return p_impl->get_reboot_suggested();
}
bool AdvisoryPackage::get_restart_suggested() const {
    return p_impl->get_restart_suggested();
}
bool AdvisoryPackage::get_relogin_suggested() const {
    return p_impl->get_relogin_suggested();
}

// AdvisoryPackage::Impl
AdvisoryPackage::Impl::Impl(
    const libdnf5::BaseWeakPtr & base,
    AdvisoryId advisory,
    int owner_collection_index,
    Id name,
    Id evr,
    Id arch,
    bool reboot_suggested,
    bool restart_suggested,
    bool relogin_suggested,
    const char * filename)
    : advisory(advisory),
      owner_collection_index(owner_collection_index),
      name(name),
      evr(evr),
      arch(arch),
      reboot_suggested(reboot_suggested),
      restart_suggested(restart_suggested),
      relogin_suggested(relogin_suggested),
      filename(filename),
      base(base) {}

std::string AdvisoryPackage::Impl::get_name() const {
    return get_rpm_pool(base).id2str(name);
}

std::string AdvisoryPackage::Impl::get_epoch() const {
    auto & pool = get_rpm_pool(base);
    return pool.split_evr(pool.id2str(evr)).e_def();
}

std::string AdvisoryPackage::Impl::get_version() const {
    auto & pool = get_rpm_pool(base);
    return pool.split_evr(pool.id2str(evr)).v;
}

std::string AdvisoryPackage::Impl::get_release() const {
    auto & pool = get_rpm_pool(base);
    return pool.split_evr(pool.id2str(evr)).r;
}

std::string AdvisoryPackage::Impl::get_evr() const {
    return get_rpm_pool(base).id2str(evr);
}

std::string AdvisoryPackage::Impl::get_arch() const {
    return get_rpm_pool(base).id2str(arch);
}

bool AdvisoryPackage::Impl::is_resolved_in(const libdnf5::rpm::PackageSet & pkgs) const {
    auto & pool = get_rpm_pool(base);
    auto sack = base->get_rpm_package_sack();
    auto & sorted_solvables = sack->p_impl->get_sorted_solvables();

    auto low = std::lower_bound(
        sorted_solvables.begin(),
        sorted_solvables.end(),
        *this,
        libdnf5::advisory::AdvisoryPackage::Impl::name_arch_compare_lower_solvable);
    while (low != sorted_solvables.end() && (*low)->name == get_name_id() && (*low)->arch == get_arch_id()) {
        int libsolv_cmp = pool.evrcmp((*low)->evr, get_evr_id(), EVRCMP_COMPARE);
        if (libsolv_cmp >= 0) {  // We are interested only in lower or equal evr
            if (pkgs.p_impl->contains(pool.solvable2id(*low))) {
                return true;
            }
        }
        ++low;
    }

    return false;
}

}  // namespace libdnf5::advisory