From 1d250815e7d6227cd643b9ec8162d162e8d9bcaf Mon Sep 17 00:00:00 2001 From: thetric Date: Tue, 7 Mar 2017 15:13:24 +0100 Subject: [PATCH] feat(common): create parent dirs + settings file if not exist this fixes an exception that occurs when the parent dirs + the file itself do not exist --- .../ui/common/prefs/UserPreferenceServiceImpl.groovy | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ui/common/src/main/groovy/com/github/thetric/iliasdownloader/ui/common/prefs/UserPreferenceServiceImpl.groovy b/ui/common/src/main/groovy/com/github/thetric/iliasdownloader/ui/common/prefs/UserPreferenceServiceImpl.groovy index ecc6f9e..4628bc6 100644 --- a/ui/common/src/main/groovy/com/github/thetric/iliasdownloader/ui/common/prefs/UserPreferenceServiceImpl.groovy +++ b/ui/common/src/main/groovy/com/github/thetric/iliasdownloader/ui/common/prefs/UserPreferenceServiceImpl.groovy @@ -5,8 +5,8 @@ import groovy.util.logging.Log4j2 import org.yaml.snakeyaml.Yaml import java.nio.charset.StandardCharsets +import java.nio.file.Files import java.nio.file.Path - /** * Created by Dominik Broj on 31.01.2016. * @@ -32,6 +32,10 @@ final class UserPreferenceServiceImpl implements UserPreferenceService { @Override void saveUserPreferences(UserPreferences userPreferences) throws IOException { + if (Files.notExists(settingsFile)) { + Files.createDirectories(settingsFile.parent) + Files.createFile settingsFile + } settingsFile.withWriter StandardCharsets.UTF_8.name(), { yaml.dump userPreferences, it }