Ensure we always keep the backup key

This commit is contained in:
Johannes Zellner
2016-10-11 15:56:07 +02:00
parent 0c85f96b27
commit f9e47ac3c0

View File

@@ -392,12 +392,19 @@ function setBackupConfig(backupConfig, callback) {
backups.testConfig(backupConfig, function (error) {
if (error) return callback(error);
settingsdb.set(exports.BACKUP_CONFIG_KEY, JSON.stringify(backupConfig), function (error) {
settingsdb.get(exports.BACKUP_CONFIG_KEY, function (error, result) {
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
exports.events.emit(exports.BACKUP_CONFIG_KEY, backupConfig);
// preserve the backup key!
backupConfig.key = JSON.parse(result).key;
callback(null);
settingsdb.set(exports.BACKUP_CONFIG_KEY, JSON.stringify(backupConfig), function (error) {
if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error));
exports.events.emit(exports.BACKUP_CONFIG_KEY, backupConfig);
callback(null);
});
});
});
}