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
(rpm-software-management#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 rpm-software-management#1084
  • Loading branch information
evan-goode committed Dec 12, 2023
1 parent 864061d commit 2b7da7b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dnf5-plugins/builddep_plugin/builddep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ bool BuildDepCommand::add_from_pkg(
}
}

std::string escape_glob(const std::string & in) {
// Escape fnmatch glob characters in a string
std::string out = std::regex_replace(in, std::regex("\\\\"), "\\\\");
out = std::regex_replace(out, std::regex("\\["), "\\[");
out = std::regex_replace(out, std::regex("\\]"), "\\]");
out = std::regex_replace(out, std::regex("\\*"), "\\*");
out = std::regex_replace(out, std::regex("\\?"), "\\?");
return out;
}

void BuildDepCommand::run() {
// get build dependencies from various inputs
std::set<std::string> install_specs{};
Expand Down Expand Up @@ -272,7 +282,8 @@ 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);
const auto & escaped_spec = escape_glob(spec);
goal->add_rpm_install(escaped_spec, settings);
}
}

Expand Down

0 comments on commit 2b7da7b

Please sign in to comment.