2017-11-28 11:00:07 +00:00
|
|
|
#include <Interpreters/ExternalLoaderConfigRepository.h>
|
|
|
|
|
2018-01-15 19:07:47 +00:00
|
|
|
#include <Common/StringUtils/StringUtils.h>
|
|
|
|
#include <Common/ConfigProcessor/ConfigProcessor.h>
|
2017-11-28 11:00:07 +00:00
|
|
|
#include <Common/getMultipleKeysFromConfig.h>
|
|
|
|
|
|
|
|
#include <Poco/Glob.h>
|
|
|
|
#include <Poco/File.h>
|
|
|
|
#include <Poco/Path.h>
|
|
|
|
|
2017-12-13 20:21:03 +00:00
|
|
|
|
2017-11-28 11:00:07 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-12-01 16:22:19 +00:00
|
|
|
ExternalLoaderConfigRepository::Files ExternalLoaderConfigRepository::list(
|
2017-11-28 11:00:07 +00:00
|
|
|
const Poco::Util::AbstractConfiguration & config,
|
|
|
|
const std::string & path_key) const
|
|
|
|
{
|
2017-12-01 16:22:19 +00:00
|
|
|
Files files;
|
2017-11-28 11:00:07 +00:00
|
|
|
|
2017-12-01 16:20:01 +00:00
|
|
|
auto patterns = getMultipleValuesFromConfig(config, "", path_key);
|
2017-11-28 11:00:07 +00:00
|
|
|
|
|
|
|
for (auto & pattern : patterns)
|
|
|
|
{
|
|
|
|
if (pattern.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (pattern[0] != '/')
|
|
|
|
{
|
|
|
|
const auto app_config_path = config.getString("config-file", "config.xml");
|
|
|
|
const auto config_dir = Poco::Path{app_config_path}.parent().toString();
|
|
|
|
const auto absolute_path = config_dir + pattern;
|
|
|
|
Poco::Glob::glob(absolute_path, files, 0);
|
|
|
|
if (!files.empty())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Poco::Glob::glob(pattern, files, 0);
|
|
|
|
}
|
|
|
|
|
2017-12-13 20:21:03 +00:00
|
|
|
for (Files::iterator it = files.begin(); it != files.end();)
|
|
|
|
{
|
|
|
|
if (ConfigProcessor::isPreprocessedFile(*it))
|
|
|
|
files.erase(it++);
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
2017-11-28 11:00:07 +00:00
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExternalLoaderConfigRepository::exists(const std::string & config_file) const
|
|
|
|
{
|
|
|
|
return Poco::File(config_file).exists();
|
|
|
|
}
|
|
|
|
|
|
|
|
Poco::Timestamp ExternalLoaderConfigRepository::getLastModificationTime(
|
|
|
|
const std::string & config_file) const
|
|
|
|
{
|
|
|
|
return Poco::File(config_file).getLastModified();
|
|
|
|
}
|
|
|
|
|
|
|
|
Poco::AutoPtr<Poco::Util::AbstractConfiguration> ExternalLoaderConfigRepository::load(
|
|
|
|
const std::string & config_file) const
|
|
|
|
{
|
|
|
|
ConfigProcessor config_processor{config_file};
|
|
|
|
ConfigProcessor::LoadedConfig preprocessed = config_processor.loadConfig();
|
|
|
|
config_processor.savePreprocessedConfig(preprocessed);
|
|
|
|
return preprocessed.configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|