From bbb07451bd7dd757a5f86d5914e522ebce47bf67 Mon Sep 17 00:00:00 2001 From: Szum123321 Date: Thu, 23 Dec 2021 20:58:55 +0100 Subject: [PATCH] #80 test --- .../textile_backup/core/Utilities.java | 20 ++++++++++++++----- .../compressors/ParallelZipCompressor.java | 18 ++++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/szum123321/textile_backup/core/Utilities.java b/src/main/java/net/szum123321/textile_backup/core/Utilities.java index f4404c1..f02b901 100644 --- a/src/main/java/net/szum123321/textile_backup/core/Utilities.java +++ b/src/main/java/net/szum123321/textile_backup/core/Utilities.java @@ -80,13 +80,23 @@ public class Utilities { return path; } - public static boolean updateTMPFSFlag(MinecraftServer server) { - Statics.disableTMPFiles = (FileUtils.sizeOfDirectory(Utilities.getWorldFolder(server)) >= - (new File(System.getProperty("java.io.tmpdir"))).getFreeSpace()); + public static void updateTMPFSFlag(MinecraftServer server) { + boolean flag = false; + 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) { diff --git a/src/main/java/net/szum123321/textile_backup/core/create/compressors/ParallelZipCompressor.java b/src/main/java/net/szum123321/textile_backup/core/create/compressors/ParallelZipCompressor.java index bab11a7..63a81c7 100644 --- a/src/main/java/net/szum123321/textile_backup/core/create/compressors/ParallelZipCompressor.java +++ b/src/main/java/net/szum123321/textile_backup/core/create/compressors/ParallelZipCompressor.java @@ -40,7 +40,7 @@ public class ParallelZipCompressor extends ZipCompressor { private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME); //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", "write", 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 { /* 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 { scatterZipCreator.writeTo((ZipArchiveOutputStream) arc); @@ -92,15 +92,13 @@ public class ParallelZipCompressor extends ZipCompressor { Throwable cause; if((cause = e.getCause()).getClass().equals(IOException.class)) { //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) { - for(int i = 0; i < STACKTRACE.length && match; i++) - if(!STACKTRACE[i].equals(cause.getStackTrace()[i])) { - //Statics.LOGGER.error("Mismatch at: {}, classname: {}, methodname: {}, {}", i, cause.getStackTrace()[i].getClassName(), cause.getStackTrace()[i].getMethodName()); - match = false; - } + for(int i = 0; i < STACKTRACE_NO_SPACE_ON_LEFT_ON_DEVICE.length && match; i++) + if(!STACKTRACE_NO_SPACE_ON_LEFT_ON_DEVICE[i].equals(cause.getStackTrace()[i])) 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); } } @@ -109,7 +107,7 @@ public class ParallelZipCompressor extends ZipCompressor { } } - private static record SimpleStackTraceElement ( + private record SimpleStackTraceElement ( String className, String methodName, boolean isNative