Skip to content

Commit

Permalink
feat(common): create parent dirs + settings file if not exist
Browse files Browse the repository at this point in the history
this fixes an exception that occurs when the parent dirs + the file itself do not exist
  • Loading branch information
thetric committed Mar 7, 2017
1 parent 7f1b91c commit 1d25081
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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
}
Expand Down

0 comments on commit 1d25081

Please sign in to comment.