mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-25 18:47:44 +01:00
Save YAML regions database to a temporary file before renaming.
This commit is contained in:
parent
504fceceeb
commit
29f804b9f0
@ -87,13 +87,13 @@ public YAMLDatabase(File file, Logger logger) throws ProtectionDatabaseException
|
||||
}
|
||||
}
|
||||
|
||||
private YAMLProcessor createYamlProcessor() {
|
||||
private YAMLProcessor createYamlProcessor(File file) {
|
||||
return new YAMLProcessor(file, false, YAMLFormat.COMPACT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performLoad() throws ProtectionDatabaseException {
|
||||
YAMLProcessor config = createYamlProcessor();
|
||||
YAMLProcessor config = createYamlProcessor(file);
|
||||
|
||||
try {
|
||||
config.load();
|
||||
@ -260,8 +260,9 @@ private DefaultDomain parseDomain(YAMLNode node) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performSave() {
|
||||
YAMLProcessor config = createYamlProcessor();
|
||||
protected void performSave() throws ProtectionDatabaseException {
|
||||
File tempFile = new File(file.getParentFile(), file.getName() + ".tmp");
|
||||
YAMLProcessor config = createYamlProcessor(tempFile);
|
||||
|
||||
config.clear();
|
||||
|
||||
@ -317,6 +318,11 @@ protected void performSave() {
|
||||
"# REMEMBER TO KEEP PERIODICAL BACKUPS.\r\n" +
|
||||
"#");
|
||||
config.save();
|
||||
|
||||
file.delete();
|
||||
if (!tempFile.renameTo(file)) {
|
||||
throw new ProtectionDatabaseException("Failed to rename temporary regions file to " + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> getFlagData(ProtectedRegion region) {
|
||||
|
Loading…
Reference in New Issue
Block a user