lib/boot: Convert bootconfig parser to new code style
This is a small one. Closes: #790 Approved by: jlebon
This commit is contained in:
parent
f6f967f8d9
commit
44456c6dc1
|
|
@ -79,23 +79,18 @@ ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
g_autofree char *contents = NULL;
|
|
||||||
char **lines = NULL;
|
|
||||||
char **iter = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (!self->parsed, FALSE);
|
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)
|
if (!contents)
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
lines = g_strsplit (contents, "\n", -1);
|
g_auto(GStrv) lines = g_strsplit (contents, "\n", -1);
|
||||||
for (iter = lines; *iter; iter++)
|
for (char **iter = lines; *iter; iter++)
|
||||||
{
|
{
|
||||||
const char *line = *iter;
|
const char *line = *iter;
|
||||||
char *keyname = "";
|
char *keyname = "";
|
||||||
|
|
||||||
if (g_ascii_isalpha (*line))
|
if (g_ascii_isalpha (*line))
|
||||||
{
|
{
|
||||||
char **items = NULL;
|
char **items = NULL;
|
||||||
|
|
@ -115,11 +110,8 @@ ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
self->parsed = TRUE;
|
self->parsed = TRUE;
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
g_strfreev (lines);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
@ -166,16 +158,10 @@ ostree_bootconfig_parser_write_at (OstreeBootconfigParser *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
g_autoptr(GString) buf = g_string_new ("");
|
||||||
GHashTableIter hashiter;
|
g_autoptr(GHashTable) written_overrides = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
gpointer hashkey, hashvalue;
|
|
||||||
GString *buf = g_string_new ("");
|
|
||||||
guint i;
|
|
||||||
g_autoptr(GHashTable) written_overrides = NULL;
|
|
||||||
|
|
||||||
written_overrides = g_hash_table_new (g_str_hash, g_str_equal);
|
for (guint i = 0; i < self->lines->len; i++)
|
||||||
|
|
||||||
for (i = 0; i < self->lines->len; i++)
|
|
||||||
{
|
{
|
||||||
GVariant *linedata = self->lines->pdata[i];
|
GVariant *linedata = self->lines->pdata[i];
|
||||||
const char *key;
|
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);
|
g_hash_table_iter_init (&hashiter, self->options);
|
||||||
while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
|
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,
|
if (!glnx_file_replace_contents_at (dfd, path, (guint8*)buf->str, buf->len,
|
||||||
GLNX_FILE_REPLACE_NODATASYNC,
|
GLNX_FILE_REPLACE_NODATASYNC,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
if (buf)
|
|
||||||
g_string_free (buf, TRUE);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ostree_bootconfig_parser_write (OstreeBootconfigParser *self,
|
ostree_bootconfig_parser_write (OstreeBootconfigParser *self,
|
||||||
GFile *output,
|
GFile *output,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue