From 44456c6dc1032619b40717881c3d8ae73ab09e5a Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 12 Apr 2017 20:50:53 -0400 Subject: [PATCH] lib/boot: Convert bootconfig parser to new code style This is a small one. Closes: #790 Approved by: jlebon --- src/libostree/ostree-bootconfig-parser.c | 46 ++++++++---------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/src/libostree/ostree-bootconfig-parser.c b/src/libostree/ostree-bootconfig-parser.c index 8031334e..a7c473dd 100644 --- a/src/libostree/ostree-bootconfig-parser.c +++ b/src/libostree/ostree-bootconfig-parser.c @@ -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,