------------------------------------------------------------------------------------ */
| 682 | |
| 683 | /* ------------------------------------------------------------------------------------ */ |
| 684 | Errata |
| 685 | Config::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 | /* ------------------------------------------------------------------------------------ */ |
| 729 | Errata |
| 730 | Config::load_file_glob(TextView pattern, swoc::TextView cfg_key, YamlCache *cache) |
no test coverage detected