From 2a0a39a95aa88a45ecc6cff4d5f7a9075c4e61d4 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Mon, 9 Aug 2021 23:35:32 +0100 Subject: [PATCH] Avoid creation of lists directory until the first item is added to a list. --- src/main/java/org/qortal/list/ResourceList.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/qortal/list/ResourceList.java b/src/main/java/org/qortal/list/ResourceList.java index 49b8aeb4..c80deac3 100644 --- a/src/main/java/org/qortal/list/ResourceList.java +++ b/src/main/java/org/qortal/list/ResourceList.java @@ -46,13 +46,7 @@ public class ResourceList { private Path getFilePath() { String pathString = String.format("%s%s%s_%s.json", Settings.getInstance().getListsPath(), File.separator, this.resourceName, this.category); - Path outputFilePath = Paths.get(pathString); - try { - Files.createDirectories(outputFilePath.getParent()); - } catch (IOException e) { - throw new IllegalStateException("Unable to create lists directory"); - } - return outputFilePath; + return Paths.get(pathString); } public void save() throws IOException { @@ -63,8 +57,15 @@ public class ResourceList { throw new IllegalStateException("Can't save list with missing category"); } String jsonString = ResourceList.listToJSONString(this.list); - Path filePath = this.getFilePath(); + + // Create parent directory if needed + try { + Files.createDirectories(filePath.getParent()); + } catch (IOException e) { + throw new IllegalStateException("Unable to create lists directory"); + } + BufferedWriter writer = new BufferedWriter(new FileWriter(filePath.toString())); writer.write(jsonString); writer.close();