1 | #include <Interpreters/ExternalLoaderXMLConfigRepository.h> |
2 | |
3 | #include <Common/StringUtils/StringUtils.h> |
4 | #include <Common/Config/ConfigProcessor.h> |
5 | #include <Common/getMultipleKeysFromConfig.h> |
6 | |
7 | #include <Poco/Glob.h> |
8 | #include <Poco/File.h> |
9 | #include <Poco/Path.h> |
10 | |
11 | |
12 | namespace DB |
13 | { |
14 | ExternalLoaderXMLConfigRepository::ExternalLoaderXMLConfigRepository( |
15 | const Poco::Util::AbstractConfiguration & main_config_, const std::string & config_key_) |
16 | : main_config(main_config_), config_key(config_key_) |
17 | { |
18 | } |
19 | |
20 | Poco::Timestamp ExternalLoaderXMLConfigRepository::getUpdateTime(const std::string & definition_entity_name) |
21 | { |
22 | return Poco::File(definition_entity_name).getLastModified(); |
23 | } |
24 | |
25 | std::set<std::string> ExternalLoaderXMLConfigRepository::getAllLoadablesDefinitionNames() |
26 | { |
27 | std::set<std::string> files; |
28 | |
29 | auto patterns = getMultipleValuesFromConfig(main_config, "" , config_key); |
30 | |
31 | for (auto & pattern : patterns) |
32 | { |
33 | if (pattern.empty()) |
34 | continue; |
35 | |
36 | if (pattern[0] != '/') |
37 | { |
38 | const auto app_config_path = main_config.getString("config-file" , "config.xml" ); |
39 | const auto config_dir = Poco::Path{app_config_path}.parent().toString(); |
40 | const auto absolute_path = config_dir + pattern; |
41 | Poco::Glob::glob(absolute_path, files, 0); |
42 | if (!files.empty()) |
43 | continue; |
44 | } |
45 | |
46 | Poco::Glob::glob(pattern, files, 0); |
47 | } |
48 | |
49 | for (std::set<std::string>::iterator it = files.begin(); it != files.end();) |
50 | { |
51 | if (ConfigProcessor::isPreprocessedFile(*it)) |
52 | files.erase(it++); |
53 | else |
54 | ++it; |
55 | } |
56 | |
57 | return files; |
58 | } |
59 | |
60 | bool ExternalLoaderXMLConfigRepository::exists(const std::string & definition_entity_name) |
61 | { |
62 | return Poco::File(definition_entity_name).exists(); |
63 | } |
64 | |
65 | Poco::AutoPtr<Poco::Util::AbstractConfiguration> ExternalLoaderXMLConfigRepository::load( |
66 | const std::string & config_file) |
67 | { |
68 | ConfigProcessor config_processor{config_file}; |
69 | ConfigProcessor::LoadedConfig preprocessed = config_processor.loadConfig(); |
70 | config_processor.savePreprocessedConfig(preprocessed, main_config.getString("path" , DBMS_DEFAULT_PATH)); |
71 | return preprocessed.configuration; |
72 | } |
73 | |
74 | } |
75 | |