MCPcopy Create free account
hub / github.com/apache/trafficserver / load_file

Method load_file

plugins/experimental/txn_box/plugin/src/Config.cc:684–727  ·  view source on GitHub ↗

------------------------------------------------------------------------------------ */

Source from the content-addressed store, hash-verified

682
683/* ------------------------------------------------------------------------------------ */
684Errata
685Config::load_file(swoc::file::path const &cfg_path, TextView cfg_key, YamlCache *cache)
686{
687 if (auto spot = _cfg_files.find(cfg_path); spot != _cfg_files.end()) {
688 if (spot->second.has_cfg_key(cfg_key)) {
689 ts::DebugMsg(R"(Skipping "{}":{} - already loaded)", cfg_path, cfg_key);
690 return {};
691 } else {
692 spot->second.add_cfg_key(cfg_key);
693 }
694 } else { // not found - put it in the table.
695 auto [iter, flag] = _cfg_files.emplace(FileInfoMap::value_type{cfg_path, {}});
696 iter->second.add_cfg_key(cfg_key);
697 }
698
699 YAML::Node root;
700 // Try loading and parsing the file.
701 if (cache) {
702 if (auto cache_spot = cache->find(cfg_path); cache_spot != cache->end()) {
703 root = cache_spot->second;
704 }
705 }
706
707 if (root.IsNull()) {
708 auto &&[yaml_node, yaml_errata]{yaml_load(cfg_path)};
709 if (!yaml_errata.is_ok()) {
710 yaml_errata.note(R"(While loading file "{}".)", cfg_path);
711 return std::move(yaml_errata);
712 }
713 root = yaml_node;
714 if (cache) {
715 cache->emplace(cfg_path, root);
716 }
717 }
718
719 // Process the YAML data.
720 auto errata = this->parse_yaml(root, cfg_key);
721 if (!errata.is_ok()) {
722 errata.note(R"(While parsing key "{}" in configuration file "{}".)", cfg_key, cfg_path);
723 return errata;
724 }
725
726 return {};
727}
728/* ------------------------------------------------------------------------------------ */
729Errata
730Config::load_file_glob(TextView pattern, swoc::TextView cfg_key, YamlCache *cache)

Callers 1

load_file_globMethod · 0.95

Calls 10

parse_yamlMethod · 0.95
DebugMsgFunction · 0.85
yaml_loadFunction · 0.85
has_cfg_keyMethod · 0.80
add_cfg_keyMethod · 0.80
emplaceMethod · 0.80
findMethod · 0.45
endMethod · 0.45
is_okMethod · 0.45
noteMethod · 0.45

Tested by

no test coverage detected