mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Update ReplxxLineReader.cpp
This commit is contained in:
parent
7003fe8258
commit
6b97fd6378
@ -72,11 +72,8 @@ ReplxxLineReader::ReplxxLineReader(
|
||||
|
||||
ReplxxLineReader::~ReplxxLineReader()
|
||||
{
|
||||
errno = 0;
|
||||
if (close(history_file_fd))
|
||||
{
|
||||
rx.print("Close of history file failed: %s\n", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
LineReader::InputStatus ReplxxLineReader::readOneLine(const String & prompt)
|
||||
@ -95,22 +92,19 @@ LineReader::InputStatus ReplxxLineReader::readOneLine(const String & prompt)
|
||||
void ReplxxLineReader::addToHistory(const String & line)
|
||||
{
|
||||
// locking history file to prevent from inconsistent concurrent changes
|
||||
errno = 0;
|
||||
bool locked = false;
|
||||
if (flock(history_file_fd, LOCK_EX))
|
||||
{
|
||||
rx.print("Lock of history file failed: %s\n", strerror(errno));
|
||||
}
|
||||
else
|
||||
locked = true;
|
||||
|
||||
rx.history_add(line);
|
||||
|
||||
// flush changes to the disk
|
||||
rx.history_save(history_file_path);
|
||||
|
||||
errno = 0;
|
||||
if (flock(history_file_fd, LOCK_UN))
|
||||
{
|
||||
if (locked && 0 != flock(history_file_fd, LOCK_UN))
|
||||
rx.print("Unlock of history file failed: %s\n", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
void ReplxxLineReader::enableBracketedPaste()
|
||||
|
Loading…
Reference in New Issue
Block a user