some cleanup

This commit is contained in:
Szum123321 2023-05-12 18:47:54 +02:00
parent 41934c32cf
commit be20e2b17a
4 changed files with 32 additions and 8 deletions

View File

@ -26,6 +26,8 @@ import net.szum123321.textile_backup.core.Utilities;
import net.szum123321.textile_backup.core.restore.AwaitThread; import net.szum123321.textile_backup.core.restore.AwaitThread;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -36,12 +38,37 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.zip.CRC32;
public class Globals { public class Globals {
public static final Globals INSTANCE = new Globals(); public static final Globals INSTANCE = new Globals();
private static final TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME); private static final TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME);
public static final DateTimeFormatter defaultDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss"); public static final DateTimeFormatter defaultDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss");
public static final Supplier<Hash> CHECKSUM_SUPPLIER = BalticHash::new; public static final Supplier<Hash> CHECKSUM_SUPPLIER = BalticHash::new;/*() -> new Hash() {
private final CRC32 crc = new CRC32();
@Override
public void update ( int b){
crc.update(b);
}
@Override
public void update ( long b) {
ByteBuffer v = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
v.putLong(b);
crc.update(v.array());
}
@Override
public void update ( byte[] b, int off, int len){
crc.update(b, off, len);
}
@Override
public long getValue () {
return crc.getValue();
}
};*/
private ExecutorService executorService = null;//TODO: AAAAAAAAAAAAAAA MEMORY LEAK!!!!!!!!! private ExecutorService executorService = null;//TODO: AAAAAAAAAAAAAAA MEMORY LEAK!!!!!!!!!
public final AtomicBoolean globalShutdownBackupFlag = new AtomicBoolean(true); public final AtomicBoolean globalShutdownBackupFlag = new AtomicBoolean(true);

View File

@ -18,14 +18,12 @@
package net.szum123321.textile_backup.core.create; package net.szum123321.textile_backup.core.create;
import org.spongepowered.include.com.google.common.collect.Maps;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class BrokenFileHandler { public class BrokenFileHandler {
private final HashMap<Path, Exception> store = Maps.newHashMap(); private final Map<Path, Exception> store = new HashMap<>();
public void handle(Path file, Exception e) { store.put(file, e); } public void handle(Path file, Exception e) { store.put(file, e); }
public boolean valid() { return store.isEmpty(); } public boolean valid() { return store.isEmpty(); }

View File

@ -21,7 +21,6 @@ import java.nio.file.Path;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
public record ExecutableBackup(@NotNull MinecraftServer server, public record ExecutableBackup(@NotNull MinecraftServer server,
ServerCommandSource commandSource, ServerCommandSource commandSource,
@ -64,7 +63,7 @@ public record ExecutableBackup(@NotNull MinecraftServer server,
log.info(builder.toString()); log.info(builder.toString());
} }
@Override @Override
public Void call() throws IOException, ExecutionException, InterruptedException { public Void call() throws Exception {
if (save) { //save the world if (save) { //save the world
log.sendInfoAL(this, "Saving server..."); log.sendInfoAL(this, "Saving server...");
server.saveAll(true, true, false); server.saveAll(true, true, false);
@ -119,7 +118,7 @@ public record ExecutableBackup(@NotNull MinecraftServer server,
} catch (Throwable e) { } catch (Throwable e) {
//ExecutorService swallows exception, so I need to catch everything //ExecutorService swallows exception, so I need to catch everything
log.error("An exception occurred when trying to create new backup file!", e); log.error("An exception occurred when trying to create a new backup file!", e);
if (ConfigHelper.INSTANCE.get().integrityVerificationMode.isStrict()) { if (ConfigHelper.INSTANCE.get().integrityVerificationMode.isStrict()) {
try { try {

View File

@ -20,7 +20,7 @@ package net.szum123321.textile_backup.core.digest;
public interface Hash { public interface Hash {
void update(int b) ; void update(int b);
void update(long b); void update(long b);