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 <javier.martinez@collabora.co.uk> https://bugzilla.gnome.org/show_bug.cgi?id=706370
This commit is contained in:
parent
2033edc658
commit
cf14b398da
|
|
@ -38,6 +38,8 @@ gboolean ot_admin_util_get_devino (GFile *path,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
char *ot_admin_join_lines (GPtrArray *lines);
|
||||||
|
|
||||||
gboolean ot_admin_parse_deploy_path_name (const char *name,
|
gboolean ot_admin_parse_deploy_path_name (const char *name,
|
||||||
char **out_csum,
|
char **out_csum,
|
||||||
int *out_serial,
|
int *out_serial,
|
||||||
|
|
|
||||||
|
|
@ -75,3 +75,27 @@ ot_admin_util_get_devino (GFile *path,
|
||||||
out:
|
out:
|
||||||
return ret;
|
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);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,30 +104,6 @@ append_config_from_boot_loader_entries (OtBootloaderSyslinux *self,
|
||||||
return ret;
|
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
|
static gboolean
|
||||||
ot_bootloader_syslinux_write_config (OtBootloader *bootloader,
|
ot_bootloader_syslinux_write_config (OtBootloader *bootloader,
|
||||||
int bootversion,
|
int bootversion,
|
||||||
|
|
@ -253,7 +229,7 @@ ot_bootloader_syslinux_write_config (OtBootloader *bootloader,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
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)
|
if (strcmp (new_config_contents, config_contents) != 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue