Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versionlock functionality for dnf5 #1121

Merged
merged 18 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bindings/libdnf5/rpm.i
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "libdnf5/rpm/reldep_list_iterator.hpp"
#include "libdnf5/rpm/rpm_signature.hpp"
#include "libdnf5/rpm/transaction_callbacks.hpp"
#include "libdnf5/rpm/versionlock_config.hpp"
%}

#define CV __perl_CV
Expand All @@ -59,6 +60,11 @@
%template(VectorNevraForm) std::vector<libdnf5::rpm::Nevra::Form>;
%template(PairBoolNevra) std::pair<bool, libdnf5::rpm::Nevra>;

%include "libdnf5/rpm/versionlock_config.hpp"

%template(VectorVersionlockCondition) std::vector<libdnf5::rpm::VersionlockCondition>;
%template(VectorVersionlockPackage) std::vector<libdnf5::rpm::VersionlockPackage>;

%include "libdnf5/rpm/package_sack.hpp"
%template(PackageSackWeakPtr) libdnf5::WeakPtr<libdnf5::rpm::PackageSack, false>;

Expand Down
4 changes: 2 additions & 2 deletions dnf5-plugins/changelog_plugin/changelog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void ChangelogCommand::run() {

std::pair<libdnf5::cli::output::ChangelogFilterType, std::variant<libdnf5::rpm::PackageQuery, int64_t, int32_t>>
filter = {libdnf5::cli::output::ChangelogFilterType::NONE, 0};
libdnf5::rpm::PackageQuery full_package_query(ctx.base, libdnf5::sack::ExcludeFlags::APPLY_EXCLUDES, false);
libdnf5::rpm::PackageQuery full_package_query(ctx.base, libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK);

auto since = since_option->get_value();
auto count = count_option->get_value();
Expand All @@ -140,7 +140,7 @@ void ChangelogCommand::run() {
}

//query
libdnf5::rpm::PackageQuery query(ctx.base, libdnf5::sack::ExcludeFlags::APPLY_EXCLUDES, true);
libdnf5::rpm::PackageQuery query(ctx.base, libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK, true);
libdnf5::ResolveSpecSettings settings{
.ignore_case = true,
.with_nevra = true,
Expand Down
2 changes: 1 addition & 1 deletion dnf5/commands/advisory/advisory_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace libdnf5::cli;

void AdvisoryInfoCommand::process_and_print_queries(
Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, const std::vector<std::string> & package_specs) {
libdnf5::rpm::PackageQuery packages(ctx.base);
libdnf5::rpm::PackageQuery packages(ctx.base, libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK);
if (package_specs.size() > 0) {
packages.filter_name(package_specs, libdnf5::sack::QueryCmp::IGLOB);
}
Expand Down
2 changes: 1 addition & 1 deletion dnf5/commands/advisory/advisory_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void AdvisoryListCommand::process_and_print_queries(
std::vector<libdnf5::advisory::AdvisoryPackage> installed_pkgs;
std::vector<libdnf5::advisory::AdvisoryPackage> not_installed_pkgs;

libdnf5::rpm::PackageQuery packages(ctx.base);
libdnf5::rpm::PackageQuery packages(ctx.base, libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK);
if (package_specs.size() > 0) {
packages.filter_name(package_specs, libdnf5::sack::QueryCmp::IGLOB);
}
Expand Down
2 changes: 1 addition & 1 deletion dnf5/commands/advisory/advisory_summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void AdvisorySummaryCommand::process_and_print_queries(
Context & ctx, libdnf5::advisory::AdvisoryQuery & advisories, const std::vector<std::string> & package_specs) {
std::string mode;

libdnf5::rpm::PackageQuery packages(ctx.base);
libdnf5::rpm::PackageQuery packages(ctx.base, libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK);
if (package_specs.size() > 0) {
packages.filter_name(package_specs, libdnf5::sack::QueryCmp::IGLOB);
}
Expand Down
2 changes: 1 addition & 1 deletion dnf5/commands/download/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void DownloadCommand::run() {
auto create_nevra_pkg_pair = [](const libdnf5::rpm::Package & pkg) { return std::make_pair(pkg.get_nevra(), pkg); };

std::map<std::string, libdnf5::rpm::Package> download_pkgs;
libdnf5::rpm::PackageQuery full_pkg_query(ctx.base);
libdnf5::rpm::PackageQuery full_pkg_query(ctx.base, libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK);
for (auto & pattern : *patterns_to_download_options) {
libdnf5::rpm::PackageQuery pkg_query(full_pkg_query);
auto option = dynamic_cast<libdnf5::OptionString *>(pattern.get());
Expand Down
2 changes: 1 addition & 1 deletion dnf5/commands/leaves/leaves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void LeavesCommand::configure() {
void LeavesCommand::run() {
auto & ctx = get_context();

libdnf5::rpm::PackageQuery leaves_package_query(ctx.base);
libdnf5::rpm::PackageQuery leaves_package_query(ctx.base, libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK);
auto leaves_package_groups = leaves_package_query.filter_leaves_groups();

for (auto & package_group : leaves_package_groups) {
Expand Down
4 changes: 2 additions & 2 deletions dnf5/commands/list/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ void ListCommand::run() {
auto & ctx = get_context();
auto & config = ctx.base.get_config();

libdnf5::rpm::PackageQuery full_package_query(ctx.base);
libdnf5::rpm::PackageQuery base_query(ctx.base);
libdnf5::rpm::PackageQuery full_package_query(ctx.base, libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK);
jan-kolarik marked this conversation as resolved.
Show resolved Hide resolved
libdnf5::rpm::PackageQuery base_query(ctx.base, libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK);

// pre-select by patterns
if (!pkg_specs.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion dnf5/commands/provides/provides.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void ProvidesCommand::run() {
std::set<std::string> unmatched_specs;

for (auto & spec : pkg_specs) {
libdnf5::rpm::PackageQuery full_package_query(ctx.base);
libdnf5::rpm::PackageQuery full_package_query(ctx.base, libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK);
// get the matched query first and the type of match (no_match, provides, file, binary) second
auto matched = filter_spec(spec, full_package_query);
for (auto package : matched.first) {
Expand Down
5 changes: 4 additions & 1 deletion dnf5/commands/repoquery/repoquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ libdnf5::rpm::PackageQuery repeat_filter(
// Create source query of all considered packages.
// To match dnf4 take arch filter into account.
// (filtering by repo and available/installed is done implicitly by loading only the required metadata)
libdnf5::rpm::PackageQuery all_considered(candidates.get_base());
libdnf5::rpm::PackageQuery all_considered(candidates.get_base(), libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK);
if (!arches.empty()) {
all_considered.filter_arch(arches, libdnf5::sack::QueryCmp::GLOB);
}
Expand Down Expand Up @@ -553,6 +553,9 @@ void RepoqueryCommand::run() {
libdnf5::sack::ExcludeFlags flags = disable_modular_filtering->get_value()
? libdnf5::sack::ExcludeFlags::IGNORE_MODULAR_EXCLUDES
: libdnf5::sack::ExcludeFlags::APPLY_EXCLUDES;
if (!upgrades->get_value()) {
flags = flags | libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK;
}
libdnf5::rpm::PackageQuery base_query(ctx.base, flags, false);
libdnf5::rpm::PackageQuery result_query(ctx.base, flags, true);

Expand Down
2 changes: 1 addition & 1 deletion dnf5/commands/search/search_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ SearchProcessor::SearchProcessor(
: base(base),
patterns(patterns),
search_all(search_all),
full_package_query(base),
full_package_query(base, libdnf5::sack::ExcludeFlags::IGNORE_VERSIONLOCK),
showdupes(show_duplicates) {
if (!showdupes) {
full_package_query.filter_latest_evr();
Expand Down
35 changes: 35 additions & 0 deletions dnf5/commands/versionlock/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright Contributors to the libdnf project.

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 General Public License as published by
the Free Software Foundation, either version 2 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#include "utils.hpp"

#include <libdnf5/utils/bgettext/bgettext-lib.h>
#include <libdnf5/utils/format.hpp>

#include <chrono>

std::string format_comment(std::string_view cmd) {
// format the comment for new config file entries
auto current_time_point = std::chrono::system_clock::now();
const std::time_t current_time = std::chrono::system_clock::to_time_t(current_time_point);
std::stringstream ss;
ss << std::put_time(std::localtime(&current_time), "%F %T");
// TODO(mblaha): add full command line
return libdnf5::utils::sformat(_("Added by 'versionlock {}' command on {}"), cmd, ss.str());
}
27 changes: 27 additions & 0 deletions dnf5/commands/versionlock/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright Contributors to the libdnf project.

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 General Public License as published by
the Free Software Foundation, either version 2 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DNF5_COMMANDS_VERSIONLOCK_UTILS_HPP
#define DNF5_COMMANDS_VERSIONLOCK_UTILS_HPP

#include <string>

std::string format_comment(std::string_view cmd);

#endif // DNF5_COMMANDS_VERSIONLOCK_UTILS_HPP
57 changes: 57 additions & 0 deletions dnf5/commands/versionlock/versionlock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright Contributors to the libdnf project.

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 General Public License as published by
the Free Software Foundation, either version 2 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#include "versionlock.hpp"

#include "versionlock_add.hpp"
#include "versionlock_clear.hpp"
#include "versionlock_delete.hpp"
#include "versionlock_exclude.hpp"
#include "versionlock_list.hpp"

namespace dnf5 {

void VersionlockCommand::set_parent_command() {
auto * arg_parser_parent_cmd = get_session().get_argument_parser().get_root_command();
auto * arg_parser_this_cmd = get_argument_parser_command();
arg_parser_parent_cmd->register_command(arg_parser_this_cmd);
arg_parser_parent_cmd->get_group("subcommands").register_argument(arg_parser_this_cmd);
}

void VersionlockCommand::set_argument_parser() {
get_argument_parser_command()->set_description("Manage versionlock configuration");
}

void VersionlockCommand::register_subcommands() {
auto * commands_group = get_context().get_argument_parser().add_new_group("versionlock_commands");
commands_group->set_header("Versionlock Commands:");
get_argument_parser_command()->register_group(commands_group);
register_subcommand(std::make_unique<VersionlockListCommand>(get_context()), commands_group);
register_subcommand(std::make_unique<VersionlockAddCommand>(get_context()), commands_group);
register_subcommand(std::make_unique<VersionlockExcludeCommand>(get_context()), commands_group);
register_subcommand(std::make_unique<VersionlockDeleteCommand>(get_context()), commands_group);
register_subcommand(std::make_unique<VersionlockClearCommand>(get_context()), commands_group);
}

void VersionlockCommand::pre_configure() {
throw_missing_command();
}


} // namespace dnf5
38 changes: 38 additions & 0 deletions dnf5/commands/versionlock/versionlock.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright Contributors to the libdnf project.

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 General Public License as published by
the Free Software Foundation, either version 2 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DNF5_COMMANDS_VERSIONLOCK_VERSIONLOCK_HPP
#define DNF5_COMMANDS_VERSIONLOCK_VERSIONLOCK_HPP

#include <dnf5/context.hpp>

namespace dnf5 {

class VersionlockCommand : public Command {
public:
explicit VersionlockCommand(Context & context) : Command(context, "versionlock") {}
void set_parent_command() override;
void set_argument_parser() override;
void register_subcommands() override;
void pre_configure() override;
};

} // namespace dnf5

#endif // DNF5_COMMANDS_VERSIONLOCK_VERSIONLOCK_HPP
Loading
Loading