From f4042903b919e2bd91f286254d7d4a317d7148c5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 4 Sep 2019 19:00:01 +0200 Subject: [PATCH] Shell: Okay I keep messing up this history file code.. actually fix it! It's not safe to return a CFile by-value. CFile is a CObjects and they are honestly not very good at being values.. --- Shell/main.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Shell/main.cpp b/Shell/main.cpp index cd645e6b38..367b01560c 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -527,21 +527,18 @@ static int run_command(const String& cmd) return return_value; } -CFile get_history_file(CIODevice::OpenMode mode) +static String get_history_path() { - StringBuilder sb; - sb.append(g.home); - sb.append("/.history"); - CFile f(sb.to_string()); - if (!f.open(mode)) - return {}; - return f; + StringBuilder builder; + builder.append(g.home); + builder.append("/.history"); + return builder.to_string(); } void load_history() { - auto history_file = get_history_file(CIODevice::ReadOnly); - if (!history_file.is_open()) + CFile history_file(get_history_path()); + if (!history_file.open(CIODevice::ReadOnly)) return; while (history_file.can_read_line()) { auto b = history_file.read_line(1024); @@ -552,8 +549,8 @@ void load_history() void save_history() { - auto history_file = get_history_file(CIODevice::WriteOnly); - if (!history_file.is_open()) + CFile history_file(get_history_path()); + if (!history_file.open(CIODevice::WriteOnly)) return; for (const auto& line : editor.history()) { history_file.write(line);