1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 19:45:10 +00:00

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..
This commit is contained in:
Andreas Kling 2019-09-04 19:00:01 +02:00
parent e12bbc097f
commit f4042903b9

View file

@ -527,21 +527,18 @@ static int run_command(const String& cmd)
return return_value; return return_value;
} }
CFile get_history_file(CIODevice::OpenMode mode) static String get_history_path()
{ {
StringBuilder sb; StringBuilder builder;
sb.append(g.home); builder.append(g.home);
sb.append("/.history"); builder.append("/.history");
CFile f(sb.to_string()); return builder.to_string();
if (!f.open(mode))
return {};
return f;
} }
void load_history() void load_history()
{ {
auto history_file = get_history_file(CIODevice::ReadOnly); CFile history_file(get_history_path());
if (!history_file.is_open()) if (!history_file.open(CIODevice::ReadOnly))
return; return;
while (history_file.can_read_line()) { while (history_file.can_read_line()) {
auto b = history_file.read_line(1024); auto b = history_file.read_line(1024);
@ -552,8 +549,8 @@ void load_history()
void save_history() void save_history()
{ {
auto history_file = get_history_file(CIODevice::WriteOnly); CFile history_file(get_history_path());
if (!history_file.is_open()) if (!history_file.open(CIODevice::WriteOnly))
return; return;
for (const auto& line : editor.history()) { for (const auto& line : editor.history()) {
history_file.write(line); history_file.write(line);