blob: 8b9584f1242b807f12b83f2ce6d7e5810b4a9d62 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include <Interpreters/ExternalLoaderXMLConfigRepository.h>
#include <filesystem>
#include <Common/StringUtils/StringUtils.h>
#include <Common/Config/ConfigProcessor.h>
#include <Common/getMultipleKeysFromConfig.h>
#include <Poco/Glob.h>
#include <Common/filesystemHelpers.h>
namespace fs = std::filesystem;
namespace DB
{
ExternalLoaderXMLConfigRepository::ExternalLoaderXMLConfigRepository(
const std::string & app_path_,
const std::string & main_config_path_,
const std::unordered_set<std::string> & patterns_)
: app_path(app_path_)
, main_config_path(main_config_path_)
, patterns(patterns_)
{
}
Poco::Timestamp ExternalLoaderXMLConfigRepository::getUpdateTime(const std::string & definition_entity_name)
{
return FS::getModificationTimestamp(definition_entity_name);
}
std::set<std::string> ExternalLoaderXMLConfigRepository::getAllLoadablesDefinitionNames()
{
std::unordered_set<std::string> patterns_copy;
{
std::lock_guard lock(patterns_mutex);
patterns_copy = patterns;
}
const String config_dir = fs::path(main_config_path).parent_path();
std::set<std::string> files;
for (const auto & pattern : patterns_copy)
{
if (pattern.empty())
continue;
if (pattern[0] != '/')
{
const String absolute_path = fs::path(config_dir) / pattern;
Poco::Glob::glob(absolute_path, files, 0);
if (!files.empty())
continue;
}
Poco::Glob::glob(pattern, files, 0);
}
for (auto it = files.begin(); it != files.end();)
{
if (ConfigProcessor::isPreprocessedFile(*it))
it = files.erase(it);
else
++it;
}
return files;
}
void ExternalLoaderXMLConfigRepository::updatePatterns(const std::unordered_set<std::string> & patterns_)
{
std::lock_guard lock(patterns_mutex);
if (patterns == patterns_)
return;
patterns = patterns_;
}
bool ExternalLoaderXMLConfigRepository::exists(const std::string & definition_entity_name)
{
return fs::exists(fs::path(definition_entity_name));
}
Poco::AutoPtr<Poco::Util::AbstractConfiguration> ExternalLoaderXMLConfigRepository::load(
const std::string & config_file)
{
ConfigProcessor config_processor{config_file};
ConfigProcessor::LoadedConfig preprocessed = config_processor.loadConfig();
config_processor.savePreprocessedConfig(preprocessed, app_path);
return preprocessed.configuration;
}
}
|