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

builddep: Don't try to expand globs in pkg specs #1085

Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 7 additions & 19 deletions dnf5-plugins/builddep_plugin/builddep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ bool BuildDepCommand::add_from_pkg(
settings.set_with_provides(false);
settings.set_with_filenames(false);
settings.set_with_binaries(false);
settings.set_expand_globs(false);
pkg_query.resolve_pkg_spec(pkg_spec, settings, false);

std::vector<std::string> source_names{pkg_spec};
Expand All @@ -218,18 +219,6 @@ bool BuildDepCommand::add_from_pkg(
}
}

std::string escape_glob(const std::string & in) {
// Escape fnmatch glob characters in a string
std::string out;
for (const auto ch : in) {
if (ch == '*' || ch == '?' || ch == '[' || ch == ']' || ch == '\\') {
out += '\\';
}
out += ch;
}
return out;
}

void BuildDepCommand::run() {
// get build dependencies from various inputs
std::set<std::string> install_specs{};
Expand Down Expand Up @@ -277,6 +266,11 @@ void BuildDepCommand::run() {
settings.set_with_nevra(false);
settings.set_with_binaries(false);

// Don't expand globs in pkg specs. The special characters in a pkg spec
// such as the brackets in `python3dist(build[virtualenv])`, should be
// treated as literal.
settings.set_expand_globs(false);

for (const auto & spec : install_specs) {
if (libdnf5::rpm::Reldep::is_rich_dependency(spec)) {
goal->add_provide_install(spec);
Expand All @@ -285,13 +279,7 @@ void BuildDepCommand::run() {
// we do not download filelists and some files could be explicitly mentioned in provide section. The best
// solution would be to merge result of provide and file search to prevent problems caused by modification
// during distro lifecycle.

// TODO(egoode) once we have a setting to disable expanding globs
// in resolve_pkg_spec, escaping the glob characters will no longer
// be needed:
// https://github.com/rpm-software-management/dnf5/pull/1085
const auto & escaped_spec = escape_glob(spec);
goal->add_rpm_install(escaped_spec, settings);
goal->add_rpm_install(spec, settings);
}
}

Expand Down
6 changes: 6 additions & 0 deletions include/libdnf5/base/goal_elements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ struct ResolveSpecSettings {
void set_with_binaries(bool with_binaries);
bool get_with_binaries() const;

/// Set whether to expand globs in package specs using fnmatch
///
/// Default: true
void set_expand_globs(bool expand_globs);
bool get_expand_globs() const;

/// When matching packages' nevras is enabled specify allowed nevra forms.
///
/// The default can be obtained from libdnf5::rpm::Nevra::get_default_pkg_spec_forms().
Expand Down
8 changes: 8 additions & 0 deletions libdnf5/base/goal_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ResolveSpecSettings::Impl {
bool with_provides{true};
bool with_filenames{true};
bool with_binaries{true};
bool expand_globs{true};
bool group_with_id{true};
bool group_with_name{false};
bool group_search_groups{true};
Expand Down Expand Up @@ -92,6 +93,13 @@ bool ResolveSpecSettings::get_with_binaries() const {
return p_impl->with_binaries;
}

void ResolveSpecSettings::set_expand_globs(bool expand_globs) {
p_impl->expand_globs = expand_globs;
}
bool ResolveSpecSettings::get_expand_globs() const {
return p_impl->expand_globs;
}

void ResolveSpecSettings::set_nevra_forms(std::vector<libdnf5::rpm::Nevra::Form> nevra_forms) {
p_impl->nevra_forms = std::move(nevra_forms);
}
Expand Down
2 changes: 1 addition & 1 deletion libdnf5/rpm/package_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ std::pair<bool, libdnf5::rpm::Nevra> PackageQuery::resolve_pkg_spec(

libdnf5::solv::SolvMap filter_result(pool.get_nsolvables());

bool glob = libdnf5::utils::is_glob_pattern(pkg_spec.c_str());
bool glob = settings.get_expand_globs() && libdnf5::utils::is_glob_pattern(pkg_spec.c_str());
libdnf5::sack::QueryCmp cmp = glob ? libdnf5::sack::QueryCmp::GLOB : libdnf5::sack::QueryCmp::EQ;
if (settings.get_with_nevra()) {
const std::vector<Nevra::Form> & test_forms =
Expand Down
Loading