浏览代码

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..
Andreas Kling 5 年之前
父节点
当前提交
f4042903b9
共有 1 个文件被更改,包括 9 次插入12 次删除
  1. 9 12
      Shell/main.cpp

+ 9 - 12
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);