Skip to content

Commit

Permalink
builddep: Escape glob characters in pkg specs
Browse files Browse the repository at this point in the history
Not parsing the pkg specs as globs would require an ABI-breaking change
(#1085). A
workaround that doesn't involve breaking changes is to escape the glob
characters in the pkg specs.

Related: rpm-software-management/mock#1267
Resolves #1084
  • Loading branch information
evan-goode authored and m-blaha committed Dec 14, 2023
1 parent 864061d commit a4662a7
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion dnf5-plugins/builddep_plugin/builddep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ 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 @@ -272,7 +284,13 @@ 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.
goal->add_rpm_install(spec, settings);

// 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);
}
}

Expand Down

0 comments on commit a4662a7

Please sign in to comment.