From bba7572d1977993cb84cbde03ce400cd9c8a39b0 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Mon, 7 Apr 2014 16:36:53 +0100 Subject: [PATCH] config: fix problems with config migration (fixes #2035, #2023) --- src/config.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index 228d1928..c73866bf 100644 --- a/src/config.c +++ b/src/config.c @@ -480,19 +480,52 @@ static void config_migrate_v3 ( void ) { char src[1024], dst[1024]; - - hts_settings_buildpath(src, sizeof(src), "input/linuxdvb/networks"); + + /* Due to having to potentially run this twice! */ hts_settings_buildpath(dst, sizeof(dst), "input/dvb/networks"); + if (!access(dst, R_OK | W_OK)) + return; + + hts_settings_makedirs(dst); + hts_settings_buildpath(src, sizeof(src), "input/linuxdvb/networks"); rename(src, dst); } +/* + * v3 -> v4 : fix broken DVB network / mux files + */ +static void +config_migrate_v5 ( void ) +{ + htsmsg_t *c, *e; + htsmsg_field_t *f; + const char *str; + + /* Remove linux prefix from class */ + if ((c = hts_settings_load_r(1, "input/dvb/networks"))) { + HTSMSG_FOREACH(f, c) { + if (!(e = htsmsg_field_get_map(f))) continue; + if (!(e = htsmsg_get_map(e, "config"))) continue; + if (!(str = htsmsg_get_str(e, "class"))) continue; + if (!strncmp(str, "linux", 5)) { + str = strdupa(str+5); + htsmsg_delete_field(e, "class"); + htsmsg_add_str(e, "class", str); + hts_settings_save(e, "input/dvb/networks/%s/config", f->hmf_name); + } + } + } +} + /* * Migration table */ static const config_migrate_t config_migrate_table[] = { config_migrate_v1, config_migrate_v2, - config_migrate_v3 + config_migrate_v3, + config_migrate_v3, // Re-run due to bug in previous version of function + config_migrate_v5 }; /*