Fix start clickhouse-client with unreadable working directory

This commit is contained in:
Anton Ivashkin 2021-06-29 17:37:12 +03:00
parent a13a7f65d8
commit 955c031474

View File

@ -10,14 +10,25 @@ namespace DB
{
bool configReadClient(Poco::Util::LayeredConfiguration & config, const std::string & home_path)
{
auto safe_exists = [](const auto & path)->bool
{
std::error_code ec;
bool res = fs::exists(path, ec);
if (ec.value() > 0)
{
LOG_ERROR(&Poco::Logger::get("ClickHouseClient"), "Can't check '{}': [{}]({})", path, ec.value(), ec.message());
}
return res;
};
std::string config_path;
if (config.has("config-file"))
config_path = config.getString("config-file");
else if (fs::exists("./clickhouse-client.xml"))
else if (safe_exists("./clickhouse-client.xml"))
config_path = "./clickhouse-client.xml";
else if (!home_path.empty() && fs::exists(home_path + "/.clickhouse-client/config.xml"))
else if (!home_path.empty() && safe_exists(home_path + "/.clickhouse-client/config.xml"))
config_path = home_path + "/.clickhouse-client/config.xml";
else if (fs::exists("/etc/clickhouse-client/config.xml"))
else if (safe_exists("/etc/clickhouse-client/config.xml"))
config_path = "/etc/clickhouse-client/config.xml";
if (!config_path.empty())