From cf14b398da3a28eb8d13d5fb1ca88a489a5df000 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Tue, 20 Aug 2013 17:54:59 +0200 Subject: [PATCH] admin: Extract ot_admin_join_config_lines() helper function ot-bootloader-syslinux.c has a join_lines() function that is rather generic and can be used in other places. Let's add it as a helper function. Signed-off-by: Javier Martinez Canillas https://bugzilla.gnome.org/show_bug.cgi?id=706370 --- src/ostree/ot-admin-functions.h | 2 ++ src/ostree/ot-admin-util.c | 24 ++++++++++++++++++++++++ src/ostree/ot-bootloader-syslinux.c | 26 +------------------------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/ostree/ot-admin-functions.h b/src/ostree/ot-admin-functions.h index a7714728..61f8b23b 100644 --- a/src/ostree/ot-admin-functions.h +++ b/src/ostree/ot-admin-functions.h @@ -38,6 +38,8 @@ gboolean ot_admin_util_get_devino (GFile *path, GCancellable *cancellable, GError **error); +char *ot_admin_join_lines (GPtrArray *lines); + gboolean ot_admin_parse_deploy_path_name (const char *name, char **out_csum, int *out_serial, diff --git a/src/ostree/ot-admin-util.c b/src/ostree/ot-admin-util.c index affe6db0..4a055788 100644 --- a/src/ostree/ot-admin-util.c +++ b/src/ostree/ot-admin-util.c @@ -75,3 +75,27 @@ ot_admin_util_get_devino (GFile *path, out: return ret; } + +char * +ot_admin_join_lines (GPtrArray *lines) +{ + GString *buf = g_string_new (""); + guint i; + gboolean prev_was_empty = FALSE; + + for (i = 0; i < lines->len; i++) + { + const char *line = lines->pdata[i]; + /* Special bit to remove extraneous empty lines */ + if (*line == '\0') + { + if (prev_was_empty || i == 0) + continue; + else + prev_was_empty = TRUE; + } + g_string_append (buf, line); + g_string_append_c (buf, '\n'); + } + return g_string_free (buf, FALSE); +} diff --git a/src/ostree/ot-bootloader-syslinux.c b/src/ostree/ot-bootloader-syslinux.c index 27eae45f..790db09a 100644 --- a/src/ostree/ot-bootloader-syslinux.c +++ b/src/ostree/ot-bootloader-syslinux.c @@ -104,30 +104,6 @@ append_config_from_boot_loader_entries (OtBootloaderSyslinux *self, return ret; } -static char * -join_lines (GPtrArray *lines) -{ - GString *buf = g_string_new (""); - guint i; - gboolean prev_was_empty = FALSE; - - for (i = 0; i < lines->len; i++) - { - const char *line = lines->pdata[i]; - /* Special bit to remove extraneous empty lines */ - if (*line == '\0') - { - if (prev_was_empty || i == 0) - continue; - else - prev_was_empty = TRUE; - } - g_string_append (buf, line); - g_string_append_c (buf, '\n'); - } - return g_string_free (buf, FALSE); -} - static gboolean ot_bootloader_syslinux_write_config (OtBootloader *bootloader, int bootversion, @@ -253,7 +229,7 @@ ot_bootloader_syslinux_write_config (OtBootloader *bootloader, cancellable, error)) goto out; - new_config_contents = join_lines (new_lines); + new_config_contents = ot_admin_join_lines (new_lines); if (strcmp (new_config_contents, config_contents) != 0) {