mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 18:15:07 +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:
parent
e12bbc097f
commit
f4042903b9
1 changed files with 9 additions and 12 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue