From a82e8138c3a189bcad85584308999782ef2516d2 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 18 Aug 2018 14:27:50 -0700 Subject: [PATCH] Fix for 1st time file saving. --- .../database/flatfile/FlatFileDatabaseConnector.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/database/flatfile/FlatFileDatabaseConnector.java b/src/main/java/world/bentobox/bentobox/database/flatfile/FlatFileDatabaseConnector.java index 5e696aabf..437c2785e 100644 --- a/src/main/java/world/bentobox/bentobox/database/flatfile/FlatFileDatabaseConnector.java +++ b/src/main/java/world/bentobox/bentobox/database/flatfile/FlatFileDatabaseConnector.java @@ -90,9 +90,11 @@ public void saveYamlFile(YamlConfiguration yamlConfig, String tableName, String tableFolder.mkdirs(); } try { - // Make a backup of file File tmpFile = new File(tableFolder, fileName + ".bak"); - Files.copy(file.toPath(), tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + if (file.exists()) { + // Make a backup of file + Files.copy(file.toPath(), tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } yamlConfig.save(file.toPath().toString()); Files.deleteIfExists(tmpFile.toPath()); } catch (Exception e) { @@ -138,7 +140,7 @@ private void commentFile(File file, Map commentMap) { plugin.logError("Could not comment config file " + file.getName() + " " + e1.getMessage()); } } - + /** * This method is necessary because Windows has problems with Files.copy and file locking. * @param source - file