static void genGlobs(std::string path, std::vector<std::string>& results, GlobLimits limits) { // Use our helped escape/replace for wildcards. replaceGlobWildcards(path); // Generate a glob set and recurse for double star. size_t glob_index = 0; while (++glob_index < kMaxRecursiveGlobs) { glob_t data; glob(path.c_str(), GLOB_TILDE | GLOB_MARK | GLOB_BRACE, nullptr, &data); size_t count = data.gl_pathc; for (size_t index = 0; index < count; index++) { results.push_back(data.gl_pathv[index]); } globfree(&data); // The end state is a non-recursive ending or empty set of matches. size_t wild = path.rfind("**"); // Allow a trailing slash after the double wild indicator. if (count == 0 || wild > path.size() || wild < path.size() - 3) { break; } path += "/**"; } // Prune results based on settings/requested glob limitations. auto end = std::remove_if( results.begin(), results.end(), [limits](const std::string& found) { return !((found[found.length() - 1] == '/' && limits & GLOB_FOLDERS) || (found[found.length() - 1] != '/' && limits & GLOB_FILES)); }); results.erase(end, results.end()); }
inline void mergeFilePath(const std::string& name, const tree_node& node, ConfigData& conf) { for (const auto& path : node.second) { // Add the exact path after converting wildcards. std::string pattern = path.second.data(); replaceGlobWildcards(pattern); conf.files[node.first].push_back(std::move(pattern)); } conf.all_data.add_child(name + "." + node.first, node.second); }
Status FilePathsConfigParserPlugin::update(const std::string& source, const ParserConfig& config) { if (config.count("file_paths") > 0) { data_.put_child("file_paths", config.at("file_paths")); } auto& accesses = data_.get_child("file_accesses"); if (config.count("file_accesses") > 0) { if (access_map_.count(source) > 0) { access_map_.erase(source); } for (const auto& category : config.at("file_accesses")) { auto path = category.second.get_value<std::string>(""); access_map_[source].push_back(path); } // Regenerate the access: for (const auto& access_source : access_map_) { for (const auto& category : access_source.second) { accesses.put(category, access_source.first); } } } Config::getInstance().removeFiles(source); for (const auto& category : data_.get_child("file_paths")) { for (const auto& path : category.second) { auto pattern = path.second.get_value<std::string>(""); if (pattern.empty()) { continue; } replaceGlobWildcards(pattern); Config::getInstance().addFile(source, category.first, pattern); } } return Status(0, "OK"); }
static void genGlobs(std::string path, std::vector<std::string>& results, GlobLimits limits) { // Use our helped escape/replace for wildcards. replaceGlobWildcards(path, limits); // Generate a glob set and recurse for double star. size_t glob_index = 0; while (++glob_index < kMaxRecursiveGlobs) { auto glob_results = platformGlob(path); for (auto const& result_path : glob_results) { results.push_back(result_path); } // The end state is a non-recursive ending or empty set of matches. size_t wild = path.rfind("**"); // Allow a trailing slash after the double wild indicator. if (glob_results.size() == 0 || wild > path.size() || wild < path.size() - 3) { break; } path += "/**"; } // Prune results based on settings/requested glob limitations. auto end = std::remove_if( results.begin(), results.end(), [limits](const std::string& found) { return !(((found[found.length() - 1] == '/' || found[found.length() - 1] == '\\') && limits & GLOB_FOLDERS) || ((found[found.length() - 1] != '/' && found[found.length() - 1] != '\\') && limits & GLOB_FILES)); }); results.erase(end, results.end()); }