mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 10:35:18 +01:00
Fix SongodaYamlConfig not creating parent directory when saving
Caused an IOException if the PluginDataDir didn't exist yet.
This commit is contained in:
parent
e7e3c3d21d
commit
b0f006aed0
@ -28,7 +28,7 @@ import java.util.logging.Logger;
|
||||
public class SongodaYamlConfig extends YamlConfiguration {
|
||||
protected final String cannotCreateBackupCopyExceptionPrefix = "Unable to create backup copy of config file: ";
|
||||
|
||||
protected final @NotNull File file;
|
||||
public final @NotNull File file;
|
||||
protected final @NotNull Logger logger;
|
||||
|
||||
private int targetVersion;
|
||||
@ -129,6 +129,8 @@ public class SongodaYamlConfig extends YamlConfiguration {
|
||||
}
|
||||
|
||||
public void save() throws IOException {
|
||||
Files.createDirectories(this.file.toPath().getParent());
|
||||
|
||||
try (Writer writer = new FileWriter(this.file)) {
|
||||
super.save(writer);
|
||||
} catch (IOException e) {
|
||||
|
@ -60,6 +60,17 @@ class SongodaYamlConfigTest {
|
||||
assertEquals("test-key: bar\n", new String(Files.readAllBytes(this.cfg)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSaveToNonExistingSubDirectory() throws IOException {
|
||||
File configFile = new File(this.tmpDir.toFile(), "testSaveToNonExistingSubDirectory/config.yml");
|
||||
|
||||
SongodaYamlConfig cfg = new SongodaYamlConfig(configFile);
|
||||
cfg.set("test-key", "bar");
|
||||
cfg.save();
|
||||
|
||||
assertEquals("test-key: bar\n", new String(Files.readAllBytes(configFile.toPath())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithVersion() throws IOException {
|
||||
SongodaYamlConfig cfg = new SongodaYamlConfig(this.cfg.toFile());
|
||||
|
Loading…
Reference in New Issue
Block a user