diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-04 15:14:12 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-04 15:16:07 +0200 |
commit | 0b1981ddae777d00fa83fec943b17bd1dafc39db (patch) | |
tree | a79b9220d55a3d81a5dd8d45982b34bc1eb609b2 /Shell | |
parent | 16de02cce0a862b62075011d5fee36564aaa959d (diff) | |
download | serenity-0b1981ddae777d00fa83fec943b17bd1dafc39db.zip |
Shell: Oops, don't exit() when ~/.history does not exist
Diffstat (limited to 'Shell')
-rw-r--r-- | Shell/main.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Shell/main.cpp b/Shell/main.cpp index 078a25ae20..cd645e6b38 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -533,18 +533,18 @@ CFile get_history_file(CIODevice::OpenMode mode) sb.append(g.home); sb.append("/.history"); CFile f(sb.to_string()); - if (!f.open(mode)) { - fprintf(stderr, "Error opening file '%s': '%s'\n", f.filename().characters(), f.error_string()); - exit(1); - } + if (!f.open(mode)) + return {}; return f; } void load_history() { - CFile history_file = get_history_file(CIODevice::ReadOnly); + auto history_file = get_history_file(CIODevice::ReadOnly); + if (!history_file.is_open()) + return; while (history_file.can_read_line()) { - const auto&b = history_file.read_line(1024); + auto b = history_file.read_line(1024); // skip the newline and terminating bytes editor.add_to_history(String(reinterpret_cast<const char*>(b.pointer()), b.size() - 2)); } @@ -552,7 +552,9 @@ void load_history() void save_history() { - CFile history_file = get_history_file(CIODevice::WriteOnly); + auto history_file = get_history_file(CIODevice::WriteOnly); + if (!history_file.is_open()) + return; for (const auto& line : editor.history()) { history_file.write(line); history_file.write("\n"); |