mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
Shell: Don't open ~/.history for writing on startup
When we only want to read the file, we should open it for reading.
This commit is contained in:
parent
cc98ea1956
commit
ce837d157f
1 changed files with 4 additions and 4 deletions
|
@ -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");
|
||||
|
|
Loading…
Add table
Reference in a new issue