Skip to content

Commit

Permalink
Merge branch 'main' into urlprotocol
Browse files Browse the repository at this point in the history
  • Loading branch information
derickdiaz authored Jan 23, 2024
2 parents 592fc85 + 1461a37 commit 6d5da08
Show file tree
Hide file tree
Showing 124 changed files with 473 additions and 289 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
- modules: Simplify finding whether profile is default in module list
- modules: Fix `ModuleProfile::is_default` method
- modules: Store if profile is default in ModuleProfile object
- Generate docs for undocummented functions so they at least show up
- Generate docs for undocumented functions so they at least show up
- Add python advisory docs
- Add advisory python API tests
- Enable AdvisoryModule bindings
Expand Down Expand Up @@ -176,7 +176,7 @@
- Abort PGP checking immediately if any checks fail
- Display warning message when any PGP checks skipped
- Don't allow main gpgcheck=0 to override repo config
- gups and environments to `history info` ouput
- gups and environments to `history info` output
- Store missing id and repoid in db for groups/environments
- Fix out-of-bounds access in Goal::Impl::add_install_to_goal
- Fix repoquery `--list`
Expand Down
29 changes: 29 additions & 0 deletions bindings/libdnf5/common.i
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,35 @@ del ClassName##__iter__
#endif
%enddef

%define add_str(ClassName)
#if defined(SWIGPYTHON)
%extend ClassName {
std::string __str__() const {
return $self->to_string();
}
}
#endif
%enddef

%define add_repr(ClassName)
#if defined(SWIGPYTHON)
%extend ClassName {
std::string __repr__() const {
return $self->to_string_description();
}
}
#endif
%enddef

%define add_hash(ClassName)
#if defined(SWIGPYTHON)
%extend ClassName {
int __hash__() const {
return $self->get_hash();
}
}
#endif
%enddef

%{
#include "libdnf5/common/sack/query.hpp"
Expand Down
8 changes: 8 additions & 0 deletions bindings/libdnf5/rpm.i
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
}
}


%{
#include "libdnf5/rpm/arch.hpp"
#include "libdnf5/rpm/checksum.hpp"
Expand Down Expand Up @@ -61,12 +62,19 @@
%include "libdnf5/rpm/package_sack.hpp"
%template(PackageSackWeakPtr) libdnf5::WeakPtr<libdnf5::rpm::PackageSack, false>;

add_str(libdnf5::rpm::Reldep)
add_repr(libdnf5::rpm::Reldep)
add_hash(libdnf5::rpm::Reldep)
%include "libdnf5/rpm/reldep.hpp"

%rename(next) libdnf5::rpm::ReldepListIterator::operator++();
%rename(value) libdnf5::rpm::ReldepListIterator::operator*();
%include "libdnf5/rpm/reldep_list_iterator.hpp"
%include "libdnf5/rpm/reldep_list.hpp"

add_str(libdnf5::rpm::Package)
add_repr(libdnf5::rpm::Package)
add_hash(libdnf5::rpm::Package)
%include "libdnf5/rpm/package.hpp"

%template(VectorPackage) std::vector<libdnf5::rpm::Package>;
Expand Down
2 changes: 1 addition & 1 deletion bindings/perl5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ elseif(PERL_INSTALLDIRS STREQUAL "vendor")
elseif(PERL_INSTALLDIRS STREQUAL "site")
set(PERL_INSTALL_PATH "${PERL_SITEARCH}")
else()
message(FATAL_ERROR "Uknown PERL_INSTALLDIRS value: ${PERL_INSTALLDIRS}")
message(FATAL_ERROR "Unknown PERL_INSTALLDIRS value: ${PERL_INSTALLDIRS}")
endif()
message(STATUS "Perl5 files will be installed to ${PERL_INSTALL_PATH}")

Expand Down
10 changes: 5 additions & 5 deletions bindings/python3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ function(add_python3_module LIBRARY_NAME MODULE_NAME)
set(SWIG_COMPILE_OPTIONS ${SWIG_COMPILE_OPTIONS}
-Wno-redundant-decls
)
# Currenly the SWIG_PYTHON_SILENT_MEMLEAK controls only whether message:
# Currently the SWIG_PYTHON_SILENT_MEMLEAK controls only whether message:
# "swig/python detected a memory leak of type '%s', no destructor found." is printed, used here:
# https://github.com/swig/swig/blob/33f6a2d0b2c3d90b928f56ddfa599afe87903f76/Lib/python/pyrun.swg#L776
# We want to supress this message due to a bug in Python part of swig.
# We want to suppress this message due to a bug in Python part of swig.
# The core of the issue is that Python Swig has a global list of types used in all swig modules. This is
# needed because the modules are interlinked eg. libdnf5::Base is used in all of them. During finalization
# of the Python runtime unused modules are cleaned up before garbage collector runs and cleans global objects.
# This can result in a situation where for example libdnf5.advisory module is destoyed, removing its types
# from the global swig types list includeing libdnf5.base.Base, and only after that a global libdnf5.base.Base
# is garbage collected which is now missing type information -> no destructor can be called -> swig want's to
# This can result in a situation where for example libdnf5.advisory module is destroyed, removing its types
# from the global swig types list including libdnf5.base.Base, and only after that a global libdnf5.base.Base
# is garbage collected which is now missing type information -> no destructor can be called -> swig wants to
# print the message
# There is an issue reported on SWIG with the same root cause: https://github.com/swig/swig/issues/2037 it
# also contains more details.
Expand Down
2 changes: 1 addition & 1 deletion common/utils/regex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#define LIBDNF5_UTILS_REGEX_HPP


// Limit the string legth, because GCC std::regex_match() exhausts a stack on very long strings.
// Limit the string length, because GCC std::regex_match() exhausts a stack on very long strings.
#define MAX_STRING_LENGTH_FOR_REGEX_MATCH 2 << 10


Expand Down
2 changes: 1 addition & 1 deletion dnf5-plugins/builddep_plugin/builddep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void BuildDepCommand::run() {
auto goal = get_context().get_goal();
goal->set_allow_erasing(allow_erasing->get_value());

// Search only for solution in provides and files. Use buildrequire with name search migh result in inconsistent
// Search only for solution in provides and files. Use buildrequire with name search might result in inconsistent
// behavior with installing dependencies of RPMs
libdnf5::GoalJobSettings settings;
settings.with_nevra = false;
Expand Down
3 changes: 2 additions & 1 deletion dnf5-plugins/config-manager_plugin/addrepo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ void ConfigManagerAddRepoCommand::set_argument_parser() {
const char * value) {
auto val = strchr(value + 1, '=');
if (!val) {
throw cli::ArgumentParserError(M_("set: Badly formatted argument value \"{}\""), std::string{value});
throw cli::ArgumentParserError(
M_("{}: Badly formatted argument value \"{}\""), std::string{"set"}, std::string{value});
}
std::string key{value, val};
std::string key_value{val + 1};
Expand Down
2 changes: 1 addition & 1 deletion dnf5-plugins/config-manager_plugin/addrepo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ConfigManagerAddRepoCommand : public Command {

/// Tests if the repositories IDs in the vector do not already exist in the configuration.
/// @param repo_ids List of repositories IDs to check.
/// @param ignore_path The file in this path will be ignored/skiped.
/// @param ignore_path The file in this path will be ignored/skipped.
/// @throws ConfigManagerError Trown if an already existent repository ID was found.
void test_if_ids_not_already_exist(
const std::vector<std::string> & repo_ids, const std::filesystem::path & ignore_path) const;
Expand Down
10 changes: 6 additions & 4 deletions dnf5-plugins/config-manager_plugin/setopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,25 @@ void ConfigManagerSetOptCommand::set_argument_parser() {
auto value = argv[i];
auto val = strchr(value + 1, '=');
if (!val) {
throw cli::ArgumentParserError(M_("optval: Badly formatted argument value \"{}\""), std::string{value});
throw cli::ArgumentParserError(
M_("{}: Badly formatted argument value \"{}\""), std::string{"optval"}, std::string{value});
}
std::string key{value, val};
std::string key_value{val + 1};
auto dot_pos = key.rfind('.');
if (dot_pos != std::string::npos) {
if (dot_pos == key.size() - 1) {
throw cli::ArgumentParserError(
M_("optval: Badly formatted argument value: Last key character cannot be '.': {}"),
M_("{}: Badly formatted argument value: Last key character cannot be '.': {}"),
std::string{"optval"},
std::string{value});
}

// Save the repository option for later processing (solving glob patter, writing to file).
// Save the repository option for later processing (solving glob pattern, writing to file).
auto repo_id = key.substr(0, dot_pos);
if (repo_id.empty()) {
throw cli::ArgumentParserError(
M_("optval: Empty repository id is not allowed: {}"), std::string{value});
M_("{}: Empty repository id is not allowed: {}"), std::string{"optval"}, std::string{value});
}
auto repo_key = key.substr(dot_pos + 1);

Expand Down
2 changes: 1 addition & 1 deletion dnf5-plugins/config-manager_plugin/setvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void ConfigManagerSetVarCommand::set_argument_parser() {
auto val = strchr(value + 1, '=');
if (!val) {
throw cli::ArgumentParserError(
M_("varval: Badly formatted argument value \"{}\""), std::string{value});
M_("{}: Badly formatted argument value \"{}\""), std::string{"varval"}, std::string{value});
}
std::string var_name{value, val};
std::string var_value{val + 1};
Expand Down
9 changes: 6 additions & 3 deletions dnf5-plugins/config-manager_plugin/unsetopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ void ConfigManagerUnsetOptCommand::set_argument_parser() {
if (dot_pos != std::string::npos) {
if (dot_pos == key.size() - 1) {
throw cli::ArgumentParserError(
M_("remove-opt: Badly formatted argument value: Last key character cannot be '.': {}"),
M_("{}: Badly formatted argument value: Last key character cannot be '.': {}"),
std::string{"remove-opt"},
std::string{value});
}

// Save the repository option for later processing (solving glob patter, writing to file).
// Save the repository option for later processing (solving glob pattern, writing to file).
auto repo_id = key.substr(0, dot_pos);
if (repo_id.empty()) {
throw cli::ArgumentParserError(
M_("remove-opt: Empty repository id is not allowed: {}"), std::string{value});
M_("{}: Empty repository id is not allowed: {}"),
std::string{"remove-opt"},
std::string{value});
}
auto repo_key = key.substr(dot_pos + 1);

Expand Down
2 changes: 1 addition & 1 deletion dnf5-plugins/copr_plugin/copr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void CoprCommand::register_subcommands() {


std::string CoprSubCommandWithID::get_project_spec() {
// The HUB specified in the COPR SPEC arguement has precedence
// The HUB specified in the COPR SPEC argument has precedence
// over the --hub argument.
std::string hubspec = opt_hub;
if (hubspec.empty())
Expand Down
3 changes: 2 additions & 1 deletion dnf5.spec
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ It supports RPM packages, modulemd modules, and comps groups & environments.
%{_mandir}/man8/dnf5-search.8.*
%{_mandir}/man8/dnf5-swap.8.*
%{_mandir}/man8/dnf5-upgrade.8.*
%{_mandir}/man7/dnf5-aliases.7.*
%{_mandir}/man7/dnf5-caching.7.*
%{_mandir}/man7/dnf5-comps.7.*
# TODO(jkolarik): filtering is not ready yet
Expand Down Expand Up @@ -362,7 +363,7 @@ Requires: libdnf5-devel%{?_isa} = %{version}-%{release}
Requires: libdnf5-cli-devel%{?_isa} = %{version}-%{release}

%description -n dnf5-devel
Develpment files for dnf5.
Development files for dnf5.

%files -n dnf5-devel
%{_includedir}/dnf5/
Expand Down
14 changes: 7 additions & 7 deletions dnf5/cmdline_aliases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool attach_named_args(
}
if (!attached_arg_id_path) {
auto msg = fmt::format(
"Mising attribute \"id_path\" for alias \"{}\" in file \"{}\"", alias_id_path, path.native());
"Missing attribute \"id_path\" for alias \"{}\" in file \"{}\"", alias_id_path, path.native());
logger.error("{}", msg);
std::cerr << msg << std::endl;
return false;
Expand Down Expand Up @@ -124,7 +124,7 @@ void load_aliases_from_toml_file(Context & context, const fs::path & config_file
std::cerr << msg << std::endl;
return;
} catch (const std::out_of_range & e) {
auto msg = fmt::format("Mising attribute \"version\" in file \"{}\"", config_file_path.native());
auto msg = fmt::format("Missing attribute \"version\" in file \"{}\"", config_file_path.native());
logger->error("{}", msg);
std::cerr << msg << std::endl;
return;
Expand Down Expand Up @@ -173,7 +173,7 @@ void load_aliases_from_toml_file(Context & context, const fs::path & config_file
} catch (const libdnf5::cli::ArgumentParserNotFoundError & e) {
auto location = element_options.location();
auto msg = fmt::format(
"Parent commant \"{}\" not found: {}: Requested in file \"{}\" on line {}: {}",
"Parent command \"{}\" not found: {}: Requested in file \"{}\" on line {}: {}",
element_parent_id_path,
e.what(),
config_file_path.native(),
Expand Down Expand Up @@ -211,7 +211,7 @@ void load_aliases_from_toml_file(Context & context, const fs::path & config_file
}
} catch (const std::out_of_range & e) {
auto msg = fmt::format(
"Mising attribute \"type\" for element \"{}\" in file \"{}\"",
"Missing attribute \"type\" for element \"{}\" in file \"{}\"",
element_id_path,
config_file_path.native());
logger->error("{}", msg);
Expand Down Expand Up @@ -288,7 +288,7 @@ void load_aliases_from_toml_file(Context & context, const fs::path & config_file

if (!header) {
auto msg = fmt::format(
"Mising attribute \"header\" for element \"{}\" in file \"{}\"",
"Missing attribute \"header\" for element \"{}\" in file \"{}\"",
element_id_path,
config_file_path.native());
logger->error("{}", msg);
Expand Down Expand Up @@ -391,7 +391,7 @@ void load_aliases_from_toml_file(Context & context, const fs::path & config_file

if (!source) {
auto msg = fmt::format(
"Mising attribute \"source\" for named argument \"{}\" in file \"{}\"",
"Missing attribute \"source\" for named argument \"{}\" in file \"{}\"",
element_id_path,
config_file_path.native());
logger->error("{}", msg);
Expand Down Expand Up @@ -604,7 +604,7 @@ void load_aliases_from_toml_file(Context & context, const fs::path & config_file

if (!attached_command) {
auto msg = fmt::format(
"Mising attribute \"attached_command\" for command \"{}\" in file \"{}\"",
"Missing attribute \"attached_command\" for command \"{}\" in file \"{}\"",
element_id_path,
config_file_path.native());
logger->error("{}", msg);
Expand Down
62 changes: 31 additions & 31 deletions dnf5/commands/download/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ void DownloadCommand::set_argument_parser() {
alldeps_option = dynamic_cast<libdnf5::OptionBool *>(
parser.add_init_value(std::unique_ptr<libdnf5::OptionBool>(new libdnf5::OptionBool(false))));

url_option = dynamic_cast<libdnf5::OptionBool *>(
parser.add_init_value(std::unique_ptr<libdnf5::OptionBool>(new libdnf5::OptionBool(false))));

auto resolve = parser.add_new_named_arg("resolve");
resolve->set_long_name("resolve");
resolve->set_description("Resolve and download needed dependencies");
Expand All @@ -85,7 +88,6 @@ void DownloadCommand::set_argument_parser() {
url->set_const_value("true");
url->link_value(url_option);


urlprotocol_valid_options = {"http", "https", "rsync", "ftp"};
urlprotocol_option = {};
auto urlprotocol = parser.add_new_named_arg("urlprotocol");
Expand All @@ -104,6 +106,7 @@ void DownloadCommand::set_argument_parser() {
urlprotocol_option.emplace(value);
return true;
});

cmd.register_named_arg(alldeps);
create_destdir_option(*this);
cmd.register_named_arg(resolve);
Expand Down Expand Up @@ -175,40 +178,37 @@ void DownloadCommand::run() {
}
}

if (!download_pkgs.empty()) {
libdnf5::repo::PackageDownloader downloader(ctx.base);

// for download command, we don't want to mark the packages for removal
downloader.force_keep_packages(true);

for (auto & [nevra, pkg] : download_pkgs) {
downloader.add(pkg);
if (url_option->get_value()) {
// If no urlprotocols are specified, then any urlprotocol is acceptable
if (urlprotocol_option.empty()) {
urlprotocol_option = urlprotocol_valid_options;
}
for (auto & [nerva, pkg] : download_pkgs) {
auto urls = pkg.get_remote_locations();
libdnf_assert(!urls.empty(), "Failed to get mirror for package: \"{}\"", pkg.get_name());
auto valid_url = std::find_if(urls.begin(), urls.end(), [this](std::string url) {
for (auto protocol : urlprotocol_option) {
if (url.starts_with(protocol)) {
return true;
}
if (download_pkgs.empty()) {
return;
}
for (auto & [nevra, pkg] : download_pkgs) {
downloader.add(pkg);
if (url_option->get_value()) {
// If no urlprotocols are specified, then any urlprotocol is acceptable
if (urlprotocol_option.empty()) {
urlprotocol_option = urlprotocol_valid_options;
}
for (auto & [nerva, pkg] : download_pkgs) {
auto urls = pkg.get_remote_locations();
libdnf_assert(!urls.empty(), "Failed to get mirror for package: \"{}\"", pkg.get_name());
auto valid_url = std::find_if(urls.begin(), urls.end(), [this](std::string url) {
for (auto protocol : urlprotocol_option) {
if (url.starts_with(protocol)) {
return true;
}
return false;
});
if (valid_url == urls.end()) {
libdnf_assert(true, "Failed to get mirror for package: \"{}\"", pkg.get_name());
}
std::cout << *valid_url << std::endl;
return false;
});
if (valid_url == urls.end()) {
libdnf_assert(true, "Failed to get mirror for package: \"{}\"", pkg.get_name());
}

std::cout << "Downloading Packages:" << std::endl;
downloader.download();
std::cout << std::endl;
std::cout << *valid_url << std::endl;
}

std::cout << "Downloading Packages:" << std::endl;
downloader.download();
std::cout << std::endl;
}
}

} // namespace dnf5
Loading

0 comments on commit 6d5da08

Please sign in to comment.