lib/boot: Convert bootconfig parser to new code style

This is a small one.

Closes: #790
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-04-12 20:50:53 -04:00 committed by Atomic Bot
parent f6f967f8d9
commit 44456c6dc1

View File

@ -79,23 +79,18 @@ ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
g_autofree char *contents = NULL;
char **lines = NULL;
char **iter = NULL;
g_return_val_if_fail (!self->parsed, FALSE);
contents = glnx_file_get_contents_utf8_at (dfd, path, NULL, cancellable, error);
g_autofree char *contents = glnx_file_get_contents_utf8_at (dfd, path, NULL, cancellable, error);
if (!contents)
goto out;
return FALSE;
lines = g_strsplit (contents, "\n", -1);
for (iter = lines; *iter; iter++)
g_auto(GStrv) lines = g_strsplit (contents, "\n", -1);
for (char **iter = lines; *iter; iter++)
{
const char *line = *iter;
char *keyname = "";
if (g_ascii_isalpha (*line))
{
char **items = NULL;
@ -115,11 +110,8 @@ ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
}
self->parsed = TRUE;
ret = TRUE;
out:
g_strfreev (lines);
return ret;
return TRUE;
}
gboolean
@ -166,16 +158,10 @@ ostree_bootconfig_parser_write_at (OstreeBootconfigParser *self,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
GHashTableIter hashiter;
gpointer hashkey, hashvalue;
GString *buf = g_string_new ("");
guint i;
g_autoptr(GHashTable) written_overrides = NULL;
g_autoptr(GString) buf = g_string_new ("");
g_autoptr(GHashTable) written_overrides = g_hash_table_new (g_str_hash, g_str_equal);
written_overrides = g_hash_table_new (g_str_hash, g_str_equal);
for (i = 0; i < self->lines->len; i++)
for (guint i = 0; i < self->lines->len; i++)
{
GVariant *linedata = self->lines->pdata[i];
const char *key;
@ -197,6 +183,8 @@ ostree_bootconfig_parser_write_at (OstreeBootconfigParser *self,
}
}
GHashTableIter hashiter;
gpointer hashkey, hashvalue;
g_hash_table_iter_init (&hashiter, self->options);
while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
{
@ -208,15 +196,11 @@ ostree_bootconfig_parser_write_at (OstreeBootconfigParser *self,
if (!glnx_file_replace_contents_at (dfd, path, (guint8*)buf->str, buf->len,
GLNX_FILE_REPLACE_NODATASYNC,
cancellable, error))
goto out;
return FALSE;
ret = TRUE;
out:
if (buf)
g_string_free (buf, TRUE);
return ret;
return TRUE;
}
gboolean
ostree_bootconfig_parser_write (OstreeBootconfigParser *self,
GFile *output,