1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:57:35 +00:00

LibLine: Ignore ENOENT errors when loading old history

A missing history file is just an empty history, so ignore that error
and replace it with an empty array.

This regressed in f93ee3142d.
This commit is contained in:
Tim Schumacher 2023-06-03 00:56:45 +02:00 committed by Andreas Kling
parent 4be5000c22
commit ad899b179f

View file

@ -250,7 +250,13 @@ void Editor::add_to_history(DeprecatedString const& line)
ErrorOr<Vector<Editor::HistoryEntry>> Editor::try_load_history(StringView path)
{
auto history_file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
auto history_file_or_error = Core::File::open(path, Core::File::OpenMode::Read);
// We ignore "No such file or directory" errors, as that is just equivalent to an empty history.
if (history_file_or_error.is_error() && history_file_or_error.error().is_errno() && history_file_or_error.error().code() == ENOENT)
return Vector<Editor::HistoryEntry> {};
auto history_file = history_file_or_error.release_value();
auto data = TRY(history_file->read_until_eof());
auto hist = StringView { data };
Vector<HistoryEntry> history;