Skip to content

Commit

Permalink
Бекап конфига при миграции со старой версии
Browse files Browse the repository at this point in the history
  • Loading branch information
YanSergey committed May 5, 2024
1 parent 05f6c4f commit c4989ff
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -216,6 +219,20 @@ public void init() {
/** Миграция настроек из конфига предыдущей версии. */
public void migrateProps() {

if (!currentVersion.toString().equals(configVersion)) {
// делаем бекап конфига
String configCopy = configPath + "_bak";
File configFile = new File(configPath);
if (configFile.exists()) {
try {
Files.copy(Path.of(configPath), Path.of(configCopy), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
LOGGER.error("Config file backup error:", e);
}
}
configVersion = currentVersion.toString();
}

if (configVersion == null) {
configVersion = "0.2.0";
servers.forEach((key, server) -> server.migrateProps(configVersion));
Expand Down

0 comments on commit c4989ff

Please sign in to comment.