Skip to content

Commit

Permalink
Fix for 1st time file saving.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Aug 18, 2018
1 parent f844b9b commit a82e813
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -138,7 +140,7 @@ private void commentFile(File file, Map<String, String> 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
Expand Down

0 comments on commit a82e813

Please sign in to comment.