2.x-1.17
Szum123321 2021-12-23 20:58:55 +01:00
parent 4d881fe940
commit bbb07451bd
2 changed files with 23 additions and 15 deletions

View File

@ -80,13 +80,23 @@ public class Utilities {
return path; return path;
} }
public static boolean updateTMPFSFlag(MinecraftServer server) { public static void updateTMPFSFlag(MinecraftServer server) {
Statics.disableTMPFiles = (FileUtils.sizeOfDirectory(Utilities.getWorldFolder(server)) >= boolean flag = false;
(new File(System.getProperty("java.io.tmpdir"))).getFreeSpace()); Path tmp_dir = Path.of(System.getProperty("java.io.tmpdir"));
if(
FileUtils.sizeOfDirectory(Utilities.getWorldFolder(server)) >=
tmp_dir.toFile().getUsableSpace()
) {
log.error("Not enough space left in TMP directory! ({})", tmp_dir);
flag = true;
}
if(Statics.disableTMPFiles) log.warn("Not enough space left in tmp directory!\n Might cause: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems"); if(!Files.isWritable(tmp_dir.resolve("test_txb_file_2137"))) {
log.error("TMP filesystem ({}) is read-only!", tmp_dir);
flag = true;
}
return Statics.disableTMPFiles; if((Statics.disableTMPFiles = flag)) log.error("Might cause: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems");
} }
public static void disableWorldSaving(MinecraftServer server) { public static void disableWorldSaving(MinecraftServer server) {

View File

@ -40,7 +40,7 @@ public class ParallelZipCompressor extends ZipCompressor {
private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME); private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME);
//These fields are used to discriminate against the issue #51 //These fields are used to discriminate against the issue #51
private final static SimpleStackTraceElement[] STACKTRACE = { private final static SimpleStackTraceElement[] STACKTRACE_NO_SPACE_ON_LEFT_ON_DEVICE = {
new SimpleStackTraceElement("sun.nio.ch.FileDispatcherImpl", "write0", true), new SimpleStackTraceElement("sun.nio.ch.FileDispatcherImpl", "write0", true),
new SimpleStackTraceElement("sun.nio.ch.FileDispatcherImpl", "write", false), new SimpleStackTraceElement("sun.nio.ch.FileDispatcherImpl", "write", false),
new SimpleStackTraceElement("sun.nio.ch.IOUtil", "writeFromNativeBuffer", false), new SimpleStackTraceElement("sun.nio.ch.IOUtil", "writeFromNativeBuffer", false),
@ -84,7 +84,7 @@ public class ParallelZipCompressor extends ZipCompressor {
protected void finish(OutputStream arc) throws InterruptedException, IOException, ExecutionException { protected void finish(OutputStream arc) throws InterruptedException, IOException, ExecutionException {
/* /*
This is perhaps the most dreadful line of this whole mess This is perhaps the most dreadful line of this whole mess
This line causes the infamous Out of space error This line causes the infamous Out of space error (#20 and #80)
*/ */
try { try {
scatterZipCreator.writeTo((ZipArchiveOutputStream) arc); scatterZipCreator.writeTo((ZipArchiveOutputStream) arc);
@ -92,15 +92,13 @@ public class ParallelZipCompressor extends ZipCompressor {
Throwable cause; Throwable cause;
if((cause = e.getCause()).getClass().equals(IOException.class)) { if((cause = e.getCause()).getClass().equals(IOException.class)) {
//The out of space exception is thrown at sun.nio.ch.FileDispatcherImpl.write0(Native Method) //The out of space exception is thrown at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
boolean match = (cause.getStackTrace().length >= STACKTRACE.length); boolean match = (cause.getStackTrace().length >= STACKTRACE_NO_SPACE_ON_LEFT_ON_DEVICE.length);
if(match) { if(match) {
for(int i = 0; i < STACKTRACE.length && match; i++) for(int i = 0; i < STACKTRACE_NO_SPACE_ON_LEFT_ON_DEVICE.length && match; i++)
if(!STACKTRACE[i].equals(cause.getStackTrace()[i])) { if(!STACKTRACE_NO_SPACE_ON_LEFT_ON_DEVICE[i].equals(cause.getStackTrace()[i])) match = false;
//Statics.LOGGER.error("Mismatch at: {}, classname: {}, methodname: {}, {}", i, cause.getStackTrace()[i].getClassName(), cause.getStackTrace()[i].getMethodName());
match = false;
}
//For clarity sake let's not throw the ExecutionException itself rather only the cause, as the EE is just the wrapper
//For clarity' sake let's not throw the ExecutionException itself rather only the cause, as the EE is just the wrapper
if(match) throw new NoSpaceLeftOnDeviceException(cause); if(match) throw new NoSpaceLeftOnDeviceException(cause);
} }
} }
@ -109,7 +107,7 @@ public class ParallelZipCompressor extends ZipCompressor {
} }
} }
private static record SimpleStackTraceElement ( private record SimpleStackTraceElement (
String className, String className,
String methodName, String methodName,
boolean isNative boolean isNative