Skip to content

Commit

Permalink
Automatically create backup of working config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeilmeier committed Apr 3, 2018
1 parent d19394a commit 533b7db
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions edge/src/io/openems/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public synchronized void readConfigFile() throws Exception {
try {
readConfigFromFile(configFile);
log.info("Read configuration from file [" + configFile.toString() + "]");
// config was read successfully: create backup of this working configuration
this.createBackupOfConfigFile();
return;
} catch (Exception e) {
log.warn("Failed to read configuration from file [" + configFile.toString() + "] ",e);
Expand Down Expand Up @@ -262,16 +264,11 @@ public void writeConfigFile() throws NotImplementedException {
public void run() {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String config = gson.toJson(jConfig);
try {
/*
* create backup of config file
*/
Files.copy(configFile, configBackupFile, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
ConfigException ex = new ConfigException(
"Unable to create backup file [" + configBackupFile.toString() + "]");
log.error(ex.getMessage(), ex);
}

/*
* create backup of config file
*/
createBackupOfConfigFile();

try {
/*
Expand Down Expand Up @@ -299,6 +296,17 @@ public void run() {
this.writeConfigExecutor.execute(writeConfigRunnable);
}

private synchronized void createBackupOfConfigFile() {
try {
log.info("Create backup file [" + configBackupFile.toString() + "]");
Files.copy(configFile, configBackupFile, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
ConfigException ex = new ConfigException(
"Unable to create backup file [" + configBackupFile.toString() + "]");
log.error(ex.getMessage(), ex);
}
}

public synchronized void parseJsonConfig(JsonObject jConfig)
throws OpenemsException {
/*
Expand Down

0 comments on commit 533b7db

Please sign in to comment.