pthread_mutex_init(&lock, NULL);
config = config_new(CONFIG_FILE_PATH);
if (!config) {
- LOG_WARN("%s unable to load config file; attempting to transcode legacy file.", __func__);
- config = btif_config_transcode(LEGACY_CONFIG_FILE_PATH);
- if (!config) {
- LOG_WARN("%s unable to transcode legacy file, starting unconfigured.", __func__);
- config = config_new_empty();
- if (!config) {
- LOG_ERROR("%s unable to allocate a config object.", __func__);
- goto error;
- }
- }
-
- if (config_save(config, CONFIG_FILE_PATH))
- unlink(LEGACY_CONFIG_FILE_PATH);
+ LOG_WARN("%s unable to load config file: %s; using backup.",
+ __func__, CONFIG_FILE_PATH);
+ config = config_new(CONFIG_BACKUP_PATH);
+ }
+ if (!config) {
+ LOG_WARN("%s unable to load backup; attempting to transcode legacy file.", __func__);
+ config = btif_config_transcode(CONFIG_LEGACY_FILE_PATH);
+ }
+ if (!config) {
+ LOG_ERROR("%s unable to transcode legacy file; creating empty config.", __func__);
+ config = config_new_empty();
+ }
+ if (!config) {
+ LOG_ERROR("%s unable to allocate a config object.", __func__);
+ goto error;
}
- btif_config_devcache_cleanup();
+ btif_config_remove_unpaired(config);
// TODO(sharvil): use a non-wake alarm for this once we have
// API support for it. There's no need to wake the system to
assert(config != NULL);
assert(alarm_timer != NULL);
- btif_config_devcache_cleanup();
-
pthread_mutex_lock(&lock);
- config_save(config, CONFIG_FILE_PATH);
+ rename(CONFIG_FILE_PATH, CONFIG_BACKUP_PATH);
+ sync();
+ config_t *config_paired = config_new_clone(config);
+ btif_config_remove_unpaired(config_paired);
+ config_save(config_paired, CONFIG_FILE_PATH);
+ config_free(config_paired);
pthread_mutex_unlock(&lock);
}