Update ReplxxLineReader.cpp

This commit is contained in:
alexey-milovidov 2020-06-06 12:51:42 +03:00 committed by GitHub
parent 7003fe8258
commit 6b97fd6378
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()