refactor: build from conventions, adopt ConsoleLogger, and colorize TTY output
This commit is contained in:
1 parent
ea6ac852e7
commit
83ec08390f
23 files changed
+172
-151
No files matched your search
+17
-1
@@ -480,6 +480,22 @@ expand_glob(const std::filesystem::path &project_root, std::string_view pattern)
|
||||
"expand_glob: project root '{}' is not a directory", project_root.string()))};
|
||||
}
|
||||
|
||||
// Patterns may be written relative to the project root or absolute paths anchored at it
|
||||
// (recipes commonly know the project's absolute location). Match against relative paths.
|
||||
std::string effective_pattern{pattern};
|
||||
{
|
||||
const std::filesystem::path raw_pattern{std::string{pattern}};
|
||||
if (raw_pattern.is_absolute()) {
|
||||
const auto rel_pattern = raw_pattern.lexically_relative(canonical_root);
|
||||
if (!rel_pattern.empty() && rel_pattern.native().starts_with("..")) {
|
||||
return std::unexpected{make_error(
|
||||
std::format("expand_glob: pattern '{}' escapes project root '{}'", pattern,
|
||||
canonical_root.string()))};
|
||||
}
|
||||
effective_pattern = rel_pattern.lexically_normal().generic_string();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> matches;
|
||||
std::filesystem::recursive_directory_iterator it{
|
||||
canonical_root, std::filesystem::directory_options::skip_permission_denied, ec};
|
||||
@@ -493,7 +509,7 @@ expand_glob(const std::filesystem::path &project_root, std::string_view pattern)
|
||||
}
|
||||
if (it->is_regular_file(ec)) {
|
||||
const std::string gen = rel.lexically_normal().generic_string();
|
||||
if (match_glob(pattern, gen)) {
|
||||
if (match_glob(effective_pattern, gen)) {
|
||||
matches.push_back(rel.lexically_normal());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user