mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-08-16 13:47:28 +02:00
Merge f43da783f6
into 901218cdb2
This commit is contained in:
commit
d60476b2b9
@ -23,10 +23,30 @@ import stirling.software.common.util.YamlHelper;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class ConfigInitializer {
|
public class ConfigInitializer {
|
||||||
|
|
||||||
|
private static final int MIN_SETTINGS_FILE_LINES = 31;
|
||||||
|
|
||||||
public void ensureConfigExists() throws IOException, URISyntaxException {
|
public void ensureConfigExists() throws IOException, URISyntaxException {
|
||||||
// 1) If settings file doesn't exist, create from template
|
// 1) If settings file doesn't exist, create from template
|
||||||
Path destPath = Paths.get(InstallationPathConfig.getSettingsPath());
|
Path destPath = Paths.get(InstallationPathConfig.getSettingsPath());
|
||||||
if (Files.notExists(destPath)) {
|
|
||||||
|
boolean settingsFileExists = Files.exists(destPath);
|
||||||
|
|
||||||
|
long lineCount = settingsFileExists ? Files.readAllLines(destPath).size() : 0;
|
||||||
|
|
||||||
|
log.info("Current settings file line count: {}", lineCount);
|
||||||
|
|
||||||
|
if (!settingsFileExists || lineCount < MIN_SETTINGS_FILE_LINES) {
|
||||||
|
if (settingsFileExists) {
|
||||||
|
// move settings.yml to settings.yml.{timestamp}.bak
|
||||||
|
Path backupPath =
|
||||||
|
Paths.get(
|
||||||
|
InstallationPathConfig.getSettingsPath()
|
||||||
|
+ "."
|
||||||
|
+ System.currentTimeMillis()
|
||||||
|
+ ".bak");
|
||||||
|
Files.move(destPath, backupPath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
log.info("Moved existing settings file to backup: {}", backupPath);
|
||||||
|
}
|
||||||
Files.createDirectories(destPath.getParent());
|
Files.createDirectories(destPath.getParent());
|
||||||
try (InputStream in =
|
try (InputStream in =
|
||||||
getClass().getClassLoader().getResourceAsStream("settings.yml.template")) {
|
getClass().getClassLoader().getResourceAsStream("settings.yml.template")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user