Skip to content

Commit

Permalink
fix(config): overwrite existing config.default.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Feb 17, 2022
1 parent cd2621d commit 10ee712
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import lombok.Getter;
import lombok.experimental.Accessors;
import net.silthus.schat.eventbus.EventBus;
Expand Down Expand Up @@ -128,7 +130,7 @@ protected final Path resolveConfigAndCreateDefaultConfig(String fileName) {
final String fileExtension = fileName.substring(fileName.lastIndexOf('.'));
final String defaultConfigName = fileName.replace(fileExtension, ".default" + fileExtension);
final Path defaultConfig = bootstrap().configDirectory().resolve(defaultConfigName);
copyDefaultConfig(fileName, defaultConfig);
copyFromResource(fileName, defaultConfig, StandardCopyOption.REPLACE_EXISTING);
}

return config;
Expand All @@ -139,15 +141,15 @@ protected final Path resolveConfig(String fileName) {

if (!Files.exists(configFile)) {
createConfigDirectory(configFile);
copyDefaultConfig(fileName, configFile);
copyFromResource(fileName, configFile);
}

return configFile;
}

private void copyDefaultConfig(String fileName, Path configFile) {
private void copyFromResource(String fileName, Path configFile, CopyOption... options) {
try (InputStream is = bootstrap().resourceAsStream(fileName)) {
Files.copy(is, configFile);
Files.copy(is, configFile, options);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 10ee712

Please sign in to comment.