summaryrefslogtreecommitdiff
path: root/src/storage.c
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2012-05-18 11:44:07 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-05-24 16:33:36 +0300
commite2e36a26363c871a6617be99cb11602115189ba5 (patch)
treee9012d3ccb6766cfe8817077bf5166e747c3c9a8 /src/storage.c
parent86cd761a6e375875ec904ea378ed61d4fc41e1b8 (diff)
downloadconnman-e2e36a26363c871a6617be99cb11602115189ba5.tar.gz
connman-e2e36a26363c871a6617be99cb11602115189ba5.tar.bz2
connman-e2e36a26363c871a6617be99cb11602115189ba5.zip
storage: Migrate services from obsolete default.profile
In order to remove the obsolete default.profile, migrate services into the new setup with per-service directories. If the service exists in the new format, it is not migrated.
Diffstat (limited to 'src/storage.c')
-rw-r--r--src/storage.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/storage.c b/src/storage.c
index a8540734..4c00ce0b 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -387,6 +387,8 @@ void __connman_storage_migrate()
GKeyFile *keyfile_def = NULL;
GKeyFile *keyfile = NULL;
GError *error = NULL;
+ char **services, **keys, *value;
+ int i, k, err;
connman_bool_t val;
/* If setting file exists, migration has been done. */
@@ -405,6 +407,56 @@ void __connman_storage_migrate()
if (keyfile_def == NULL)
goto done;
+ services = g_key_file_get_groups(keyfile_def, NULL);
+ for (i = 0; services != NULL && services[i] != NULL; i++) {
+ if (strncmp(services[i], "wifi_", 5) != 0 &&
+ strncmp(services[i], "ethernet_", 9) != 0 &&
+ strncmp(services[i], "cellular_", 9) != 0 &&
+ strncmp(services[i], "bluetooth_", 10) != 0 &&
+ strncmp(services[i], "wimax_", 6) != 0 &&
+ strncmp(services[i], "vpn_", 4) != 0)
+ continue;
+
+ keyfile = connman_storage_load_service(services[i]);
+ if (keyfile != NULL) {
+ g_key_file_free(keyfile);
+ DBG("already exists %s", services[i]);
+ continue;
+ }
+
+ keyfile = g_key_file_new();
+ if (keyfile == NULL) {
+ connman_warn("Migrating %s failed", services[i]);
+ continue;
+ }
+
+ keys = g_key_file_get_keys(keyfile_def, services[i],
+ NULL, NULL);
+
+ for (k = 0; keys != NULL && keys[k] != NULL; k++) {
+ value = g_key_file_get_value(keyfile_def, services[i],
+ keys[k], NULL);
+ g_key_file_set_value(keyfile, services[i],
+ keys[k], value);
+ g_free(value);
+ }
+
+ if (keys != NULL && keys[0] != NULL) {
+ err = __connman_storage_save_service(keyfile,
+ services[i]);
+ if (err >= 0)
+ DBG("migrated %s", services[i]);
+ else
+ connman_warn("Migrating %s failed %s",
+ services[i], strerror(-err));
+ } else
+ DBG("no keys in %s", services[i]);
+
+ g_strfreev(keys);
+ g_key_file_free(keyfile);
+ }
+ g_strfreev(services);
+
/* Copy global settings from default.profile to settings. */
keyfile = g_key_file_new();