Skip to content

Commit

Permalink
builddep: Don't escape globs, use expand_globs = false
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-goode committed Mar 14, 2024
1 parent a2af49a commit 63f3d89
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
22 changes: 2 additions & 20 deletions dnf5-plugins/builddep_plugin/builddep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,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 @@ -281,7 +269,7 @@ void BuildDepCommand::run() {
// 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.expand_globs = false;
settings.set_expand_globs(false);

for (const auto & spec : install_specs) {
if (libdnf5::rpm::Reldep::is_rich_dependency(spec)) {
Expand All @@ -291,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
1 change: 0 additions & 1 deletion include/libdnf5/base/goal_elements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ struct ResolveSpecSettings {
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
7 changes: 7 additions & 0 deletions libdnf5/base/goal_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,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 = settings.expand_globs && 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

0 comments on commit 63f3d89

Please sign in to comment.