summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2023-06-03 00:56:45 +0200
committerAndreas Kling <kling@serenityos.org>2023-06-03 05:52:52 +0200
commitad899b179fbdb3e1ac1e80be2c09b612c031def5 (patch)
tree432077e4af61f3609fa364404f325ac456554664 /Userland
parent4be5000c22a0cb1d7201f01a1c851783170ad2e2 (diff)
downloadserenity-ad899b179fbdb3e1ac1e80be2c09b612c031def5.zip
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 f93ee3142d2ca4329d989dd917fc27c912b60806.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibLine/Editor.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp
index 841c41269f..6b37a30ac9 100644
--- a/Userland/Libraries/LibLine/Editor.cpp
+++ b/Userland/Libraries/LibLine/Editor.cpp
@@ -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;