gbookmarkfile: Do not try to write invalid modified stamp

In some bookmarks that we load the modified value may be not set, while
this may lead to a load error, we still can dump such file and this
would fail as we try to get a string from an invalid time.

Avoid this, because it would also lead to not writing a valid count
value, given that we'd pass NULL to g_strconcat too early.
This commit is contained in:
Marco Trevisan (Treviño) 2022-10-12 15:57:48 +02:00 committed by Philip Withnall
parent 870fc6763e
commit 5f604460ef

View File

@ -300,14 +300,27 @@ bookmark_app_info_dump (BookmarkAppInfo *app_info)
name = g_markup_escape_text (app_info->name, -1);
exec = g_markup_escape_text (app_info->exec, -1);
modified = g_date_time_format_iso8601 (app_info->stamp);
count = g_strdup_printf ("%u", app_info->count);
if (app_info->stamp)
{
char *tmp;
tmp = g_date_time_format_iso8601 (app_info->stamp);
modified = g_strconcat (" " BOOKMARK_MODIFIED_ATTRIBUTE "=\"", tmp, "\"",
NULL);
g_free (tmp);
}
else
{
modified = g_strdup ("");
}
retval = g_strconcat (" "
"<" BOOKMARK_NAMESPACE_NAME ":" BOOKMARK_APPLICATION_ELEMENT
" " BOOKMARK_NAME_ATTRIBUTE "=\"", name, "\""
" " BOOKMARK_EXEC_ATTRIBUTE "=\"", exec, "\""
" " BOOKMARK_MODIFIED_ATTRIBUTE "=\"", modified, "\""
" " BOOKMARK_EXEC_ATTRIBUTE "=\"", exec, "\"",
modified,
" " BOOKMARK_COUNT_ATTRIBUTE "=\"", count, "\"/>\n",
NULL);