From ce837d157ff238c59ccbdb40aaf811a9fa627dad Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 4 Sep 2019 14:59:29 +0200 Subject: [PATCH] Shell: Don't open ~/.history for writing on startup When we only want to read the file, we should open it for reading. --- Shell/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Shell/main.cpp b/Shell/main.cpp index 67b4942e11..078a25ae20 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -527,13 +527,13 @@ static int run_command(const String& cmd) return return_value; } -CFile get_history_file() +CFile get_history_file(CIODevice::OpenMode mode) { StringBuilder sb; sb.append(g.home); sb.append("/.history"); CFile f(sb.to_string()); - if (!f.open(CIODevice::ReadWrite)) { + if (!f.open(mode)) { fprintf(stderr, "Error opening file '%s': '%s'\n", f.filename().characters(), f.error_string()); exit(1); } @@ -542,7 +542,7 @@ CFile get_history_file() void load_history() { - CFile history_file = get_history_file(); + CFile history_file = get_history_file(CIODevice::ReadOnly); while (history_file.can_read_line()) { const auto&b = history_file.read_line(1024); // skip the newline and terminating bytes @@ -552,7 +552,7 @@ void load_history() void save_history() { - CFile history_file = get_history_file(); + CFile history_file = get_history_file(CIODevice::WriteOnly); for (const auto& line : editor.history()) { history_file.write(line); history_file.write("\n");