fix mantle write failing on windows

This commit is contained in:
Julian Krings 2025-06-06 16:49:42 +02:00
parent 5705caa1ba
commit 2ee22db072
No known key found for this signature in database
GPG Key ID: 208C6E08C3B718D2
2 changed files with 12 additions and 7 deletions

View File

@ -34,6 +34,7 @@ import com.volmit.iris.util.documentation.RegionCoordinates;
import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form; import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.function.Consumer4; import com.volmit.iris.util.function.Consumer4;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.M;
import com.volmit.iris.util.matter.Matter; import com.volmit.iris.util.matter.Matter;
import com.volmit.iris.util.matter.MatterSlice; import com.volmit.iris.util.matter.MatterSlice;
@ -84,7 +85,7 @@ public class Mantle {
this.worldHeight = worldHeight; this.worldHeight = worldHeight;
this.ioTrim = new AtomicBoolean(false); this.ioTrim = new AtomicBoolean(false);
this.ioTectonicUnload = new AtomicBoolean(false); this.ioTectonicUnload = new AtomicBoolean(false);
dataFolder.mkdirs(); new File(dataFolder, ".tmp").mkdirs();
loadedRegions = new KMap<>(); loadedRegions = new KMap<>();
lastUse = new KMap<>(); lastUse = new KMap<>();
ioBurst = MultiBurst.burst; ioBurst = MultiBurst.burst;
@ -387,6 +388,7 @@ public class Mantle {
} }
})); }));
loadedRegions.clear(); loadedRegions.clear();
IO.delete(new File(dataFolder, ".tmp"));
try { try {
b.complete(); b.complete();

View File

@ -222,14 +222,17 @@ public class TectonicPlate {
*/ */
public void write(File file) throws IOException { public void write(File file) throws IOException {
PrecisionStopwatch p = PrecisionStopwatch.start(); PrecisionStopwatch p = PrecisionStopwatch.start();
File temp = File.createTempFile("iris-tectonic-plate", ".bin"); File temp = File.createTempFile("iris-tectonic-plate", ".bin", new File(file.getParentFile(), ".tmp"));
try {
try (DataOutputStream dos = new DataOutputStream(new LZ4BlockOutputStream(new FileOutputStream(temp)))) { try (DataOutputStream dos = new DataOutputStream(new LZ4BlockOutputStream(new FileOutputStream(temp)))) {
write(dos); write(dos);
} }
Files.move(temp.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); Files.move(temp.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
Iris.debug("Saved Tectonic Plate " + C.DARK_GREEN + file.getName() + C.RED + " in " + Form.duration(p.getMilliseconds(), 2)); Iris.debug("Saved Tectonic Plate " + C.DARK_GREEN + file.getName() + C.RED + " in " + Form.duration(p.getMilliseconds(), 2));
} finally {
temp.delete(); temp.delete();
} }
}
/** /**
* Write this tectonic plate to a data stream * Write this tectonic plate to a data stream