storage: Remove default.profile when migration has been done
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Fri, 18 May 2012 08:44:08 +0000 (11:44 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 24 May 2012 13:33:43 +0000 (16:33 +0300)
Unconditionally remove default.profile without any migration if
the currently used global settings save file exists. The current
settings formats for global and service settings were introduced
in version 0.78.

src/storage.c

index 4c00ce0..5fcec55 100644 (file)
@@ -387,21 +387,24 @@ void __connman_storage_migrate()
        GKeyFile *keyfile_def = NULL;
        GKeyFile *keyfile = NULL;
        GError *error = NULL;
+       connman_bool_t delete_old_config = TRUE;
        char **services, **keys, *value;
        int i, k, err;
        connman_bool_t val;
 
+       pathname = g_strdup_printf("%s/%s", STORAGEDIR, DEFAULT);
+       if (pathname == NULL)
+               return;
+
        /* If setting file exists, migration has been done. */
        keyfile = __connman_storage_load_global();
        if (keyfile) {
                g_key_file_free(keyfile);
+               unlink(pathname);
+               g_free(pathname);
                return;
        }
 
-       pathname = g_strdup_printf("%s/%s", STORAGEDIR, DEFAULT);
-       if(pathname == NULL)
-               return;
-
        /* If default.profile exists, create new settings file */
        keyfile_def = storage_load(pathname);
        if (keyfile_def == NULL)
@@ -427,6 +430,7 @@ void __connman_storage_migrate()
                keyfile = g_key_file_new();
                if (keyfile == NULL) {
                        connman_warn("Migrating %s failed", services[i]);
+                       delete_old_config = FALSE;
                        continue;
                }
 
@@ -446,9 +450,11 @@ void __connman_storage_migrate()
                                        services[i]);
                        if (err >= 0)
                                DBG("migrated %s", services[i]);
-                       else
+                       else {
                                connman_warn("Migrating %s failed %s",
                                                services[i], strerror(-err));
+                               delete_old_config = FALSE;
+                       }
                } else
                        DBG("no keys in %s", services[i]);
 
@@ -520,12 +526,19 @@ void __connman_storage_migrate()
        g_key_file_set_boolean(keyfile, "WiMAX",
                                        "Enable", val);
 
-       __connman_storage_save_global(keyfile);
+       if (__connman_storage_save_global(keyfile) < 0) {
+               connman_warn("Migrating global config failed");
+               delete_old_config = FALSE;
+       }
 
        g_key_file_free(keyfile);
 
        g_key_file_free(keyfile_def);
 
+       if (delete_old_config == TRUE) {
+               DBG("migration done for %s", pathname);
+               unlink(pathname);
+       }
 done:
        g_free(pathname);
 }