Compare commits

...

3 Commits

Author SHA1 Message Date
83958f020e fix bug 2025-04-28 10:21:51 +02:00
9f8b696028 make parsing of entries easier 2025-04-28 10:21:41 +02:00
6aeafe34c3 switch to reading read-only
There is no need to writing into the journals
2025-04-28 08:52:11 +02:00
3 changed files with 23 additions and 8 deletions

View File

@ -21,6 +21,8 @@ G_DECLARE_DERIVABLE_TYPE(
EDJournalEntry *ed_journal_entry_new(void);
EDJournalEntry *ed_journal_entry_new_parse(gchar const *line, GError **error);
EDErrorCode ed_journal_entry_parse(EDJournalEntry *self,
gchar const *line,
GError **error);

View File

@ -45,6 +45,22 @@ EDJournalEntry *ed_journal_entry_new(void)
);
}
EDJournalEntry *ed_journal_entry_new_parse(gchar const *line, GError **error)
{
EDJournalEntry *e = ed_journal_entry_new();
return_if_true(e == NULL, NULL);
EDErrorCode ret = ed_error_internal;
ret = ed_journal_entry_parse(e, line, error);
if (ED_ERROR(ret)) {
g_clear_object(&e);
return NULL;
}
return e;
}
EDErrorCode ed_journal_entry_parse(EDJournalEntry *self,
gchar const *line,
GError **error)

View File

@ -209,7 +209,7 @@ static EDErrorCode ed_journal_file_load(EDJournalFile *self,
EDJournalFilePrivate *p = ed_journal_file_get_instance_private(self);
GFile *file = NULL;
GFileIOStream *stream = NULL;
GFileInputStream *stream = NULL;
GDataInputStream *reader = NULL;
EDJournalEntry *entry = NULL;
GError *e = NULL;
@ -219,15 +219,13 @@ static EDErrorCode ed_journal_file_load(EDJournalFile *self,
file = g_file_new_for_path(p->filename);
goto_if_true(file == NULL, done);
stream = g_file_open_readwrite(file, NULL, &e);
stream = g_file_read(file, NULL, &e);
if (stream == NULL) {
g_propagate_error(error, e);
goto done;
}
reader = g_data_input_stream_new(
g_io_stream_get_input_stream(G_IO_STREAM(stream))
);
reader = g_data_input_stream_new(G_INPUT_STREAM(stream));
if (reader == NULL) {
goto done;
}
@ -252,13 +250,12 @@ static EDErrorCode ed_journal_file_load(EDJournalFile *self,
g_free(line);
line = NULL;
linelen = 0;
continue;
}
entry = ed_journal_entry_new();
entry = ed_journal_entry_new_parse(line, NULL);
goto_if_true(entry == NULL, done);
ret = ed_journal_entry_parse(entry, line, NULL);
g_free(line);
line = NULL;
linelen = 0;