Skip to content

Commit fb70bd6

Browse files
committed
Remove our custom save data temp file code, as neoforge now writes save data more resiliently itself
1 parent 945f9f6 commit fb70bd6

File tree

1 file changed

+0
-31
lines changed

1 file changed

+0
-31
lines changed

src/main/java/mekanism/common/lib/MekanismSavedData.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
package mekanism.common.lib;
22

3-
import java.io.File;
4-
import java.io.IOException;
5-
import java.nio.file.AtomicMoveNotSupportedException;
6-
import java.nio.file.Files;
7-
import java.nio.file.Path;
8-
import java.nio.file.StandardCopyOption;
93
import java.util.function.Supplier;
104
import mekanism.common.Mekanism;
115
import net.minecraft.core.HolderLookup;
@@ -20,31 +14,6 @@ public abstract class MekanismSavedData extends SavedData {
2014

2115
public abstract void load(@NotNull CompoundTag nbt, @NotNull HolderLookup.Provider provider);
2216

23-
@Override
24-
public void save(@NotNull File file, @NotNull HolderLookup.Provider provider) {
25-
if (isDirty()) {
26-
//This is loosely based on Refined Storage's RSSavedData's system of saving first to a temp file
27-
// to reduce the odds of corruption if the user's computer crashes while the file is being written
28-
Path targetPath = file.toPath();
29-
Path tempPath = file.toPath().getParent().resolve(file.getName() + ".tmp");
30-
File tempFile = tempPath.toFile();
31-
super.save(tempFile, provider);
32-
//Based on Applied Energistics' AESavedData by starting to try with using an atomic move, and then only falling back to the replacing
33-
if (tempFile.exists()) {
34-
//Note: We check that the temp file exists, as if it doesn't that means we failed to write it and super will log the failure
35-
try {
36-
try {
37-
Files.move(tempPath, targetPath, StandardCopyOption.ATOMIC_MOVE);
38-
} catch (AtomicMoveNotSupportedException ignored) {
39-
Files.move(tempPath, targetPath, StandardCopyOption.REPLACE_EXISTING);
40-
}
41-
} catch (IOException e) {
42-
Mekanism.logger.error("Could not replace save data {} with new value", this, e);
43-
}
44-
}
45-
}
46-
}
47-
4817
/**
4918
* Note: This should only be called from the server side
5019
*/

0 commit comments

Comments
 (0)