dbms: Client: don't require HOME environment variable [#METR-9900].

This commit is contained in:
Alexey Milovidov 2014-02-05 13:40:20 +00:00
parent 16fd573314
commit 82d2733469

View File

@ -192,16 +192,14 @@ private:
("q")("й")("\\q")("\\Q"); ("q")("й")("\\q")("\\Q");
const char * home_path_cstr = getenv("HOME"); const char * home_path_cstr = getenv("HOME");
if (!home_path_cstr) if (home_path_cstr)
throw Exception("Cannot get HOME environment variable");
else
home_path = home_path_cstr; home_path = home_path_cstr;
if (config().has("config-file")) if (config().has("config-file"))
loadConfiguration(config().getString("config-file")); loadConfiguration(config().getString("config-file"));
else if (Poco::File("./clickhouse-client.xml").exists()) else if (Poco::File("./clickhouse-client.xml").exists())
loadConfiguration("./clickhouse-client.xml"); loadConfiguration("./clickhouse-client.xml");
else if (Poco::File(home_path + "/.clickhouse-client/config.xml").exists()) else if (!home_path.empty() && Poco::File(home_path + "/.clickhouse-client/config.xml").exists())
loadConfiguration(home_path + "/.clickhouse-client/config.xml"); loadConfiguration(home_path + "/.clickhouse-client/config.xml");
else if (Poco::File("/etc/clickhouse-client/config.xml").exists()) else if (Poco::File("/etc/clickhouse-client/config.xml").exists())
loadConfiguration("/etc/clickhouse-client/config.xml"); loadConfiguration("/etc/clickhouse-client/config.xml");
@ -280,7 +278,13 @@ private:
rl_bind_key('\t', rl_insert); rl_bind_key('\t', rl_insert);
/// Загружаем историю команд, если есть. /// Загружаем историю команд, если есть.
history_file = config().getString("history_file", home_path + "/.clickhouse-client-history"); if (config().has("history_file"))
history_file = config().getString("history_file");
else if (!home_path.empty())
history_file = home_path + "/.clickhouse-client-history";
if (!history_file.empty())
{
if (Poco::File(history_file).exists()) if (Poco::File(history_file).exists())
{ {
int res = read_history(history_file.c_str()); int res = read_history(history_file.c_str());
@ -289,6 +293,7 @@ private:
} }
else /// Создаём файл с историей. else /// Создаём файл с историей.
Poco::File(history_file).createFile(); Poco::File(history_file).createFile();
}
/// Инициализируем DateLUT, чтобы потраченное время не отображалось, как время, потраченное на запрос. /// Инициализируем DateLUT, чтобы потраченное время не отображалось, как время, потраченное на запрос.
DateLUTSingleton::instance(); DateLUTSingleton::instance();
@ -389,7 +394,7 @@ private:
{ {
add_history(query.c_str()); add_history(query.c_str());
if (append_history(1, history_file.c_str())) if (!history_file.empty() && append_history(1, history_file.c_str()))
throwFromErrno("Cannot append history to file " + history_file, ErrorCodes::CANNOT_APPEND_HISTORY); throwFromErrno("Cannot append history to file " + history_file, ErrorCodes::CANNOT_APPEND_HISTORY);
prev_query = query; prev_query = query;