From b9af3b37775c6d07f44c95b729f34ff21cfd6e7d Mon Sep 17 00:00:00 2001 From: Szum123321 Date: Wed, 10 May 2023 23:32:54 +0200 Subject: [PATCH] YYYYEEEEEEEEEEEEEEEEEEe I finally debugged the hash!!!!! The problem was due to an error in usage o FileTreeHashBuilder during unpacking. --- gradle.properties | 8 ++++---- .../net/szum123321/textile_backup/TextileBackup.java | 5 ----- .../szum123321/textile_backup/core/Utilities.java | 4 +--- .../textile_backup/core/digest/BalticHash.java | 4 ++-- .../core/digest/FileTreeHashBuilder.java | 12 +++++------- .../szum123321/textile_backup/core/digest/Hash.java | 3 +-- .../core/digest/HashingInputStream.java | 2 -- .../core/digest/HashingOutputStream.java | 2 +- src/main/resources/fabric.mod.json | 2 +- 9 files changed, 15 insertions(+), 27 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2c79c99..5ddf9f0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,18 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G -minecraft_version=23w18a -yarn_mappings=23w18a+build.5 +minecraft_version=1.20-pre1 +yarn_mappings=1.20-pre1+build.2 loader_version=0.14.19 #Fabric api -fabric_version=0.80.1+1.20 +fabric_version=0.80.2+1.20 #Cloth Config cloth_version=11.0.97 #ModMenu -modmenu_version=6.2.2 +modmenu_version=7.0.0-beta.2 databreaker_version=0.2.10 diff --git a/src/main/java/net/szum123321/textile_backup/TextileBackup.java b/src/main/java/net/szum123321/textile_backup/TextileBackup.java index 4d10e03..876bc5b 100644 --- a/src/main/java/net/szum123321/textile_backup/TextileBackup.java +++ b/src/main/java/net/szum123321/textile_backup/TextileBackup.java @@ -60,11 +60,6 @@ public class TextileBackup implements ModInitializer { log.info("Starting Textile Backup {} by Szum123321", Globals.INSTANCE.getCombinedVersionString()); - if(FabricLoader.getInstance().isDevelopmentEnvironment()) { - //Run the tests - BalticHashTest.run(); - } - ConfigHelper.updateInstance(AutoConfig.register(ConfigPOJO.class, JanksonConfigSerializer::new)); ServerTickEvents.END_SERVER_TICK.register(BackupScheduler::tick); 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 8a3ff02..7d82400 100644 --- a/src/main/java/net/szum123321/textile_backup/core/Utilities.java +++ b/src/main/java/net/szum123321/textile_backup/core/Utilities.java @@ -115,9 +115,7 @@ public class Utilities { } public static boolean isBlacklisted(Path path) { - if(isWindows()) { //hotfix! - if (path.getFileName().toString().equals("session.lock")) return true; - } + if (path.getFileName().equals("session.lock")) return true; if(path.getFileName().endsWith(CompressionStatus.DATA_FILENAME)) return true; diff --git a/src/main/java/net/szum123321/textile_backup/core/digest/BalticHash.java b/src/main/java/net/szum123321/textile_backup/core/digest/BalticHash.java index 2be911e..1b6ab70 100644 --- a/src/main/java/net/szum123321/textile_backup/core/digest/BalticHash.java +++ b/src/main/java/net/szum123321/textile_backup/core/digest/BalticHash.java @@ -38,8 +38,8 @@ public class BalticHash implements Hash { protected final ByteBuffer buffer = ByteBuffer.wrap(_byte_buffer).order(ByteOrder.LITTLE_ENDIAN); protected long hashed_data_length = 0; - public void update(byte b) { - buffer.put(b); + public void update(int b) { + buffer.put((byte)b); hashed_data_length += 1; if (buffer.position() >= buffer_limit) round(); } diff --git a/src/main/java/net/szum123321/textile_backup/core/digest/FileTreeHashBuilder.java b/src/main/java/net/szum123321/textile_backup/core/digest/FileTreeHashBuilder.java index aebb394..6e42232 100644 --- a/src/main/java/net/szum123321/textile_backup/core/digest/FileTreeHashBuilder.java +++ b/src/main/java/net/szum123321/textile_backup/core/digest/FileTreeHashBuilder.java @@ -36,13 +36,11 @@ import java.util.concurrent.atomic.AtomicBoolean; public class FileTreeHashBuilder { private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME); private final Object lock = new Object(); - private long hash = 0, filesToProcess, filesTotalSize = 0; - private final AtomicBoolean closed = new AtomicBoolean(false); + private long hash = 0, filesProcessed = 0, filesTotalSize = 0; private final CountDownLatch latch; public FileTreeHashBuilder(int filesToProcess) { - this.filesToProcess = filesToProcess; latch = new CountDownLatch(filesToProcess); } @@ -55,23 +53,23 @@ public class FileTreeHashBuilder { synchronized (lock) { this.hash ^= newHash; - filesToProcess--; filesTotalSize += size; + filesProcessed++; } } public int getRemaining() { return (int) latch.getCount(); } - synchronized public long getValue(boolean lock) throws InterruptedException { + public long getValue(boolean lock) throws InterruptedException { long leftover = latch.getCount(); if(lock) latch.await(); else if(leftover != 0) log.warn("Finishing with {} files unprocessed!", leftover); var hasher = Globals.CHECKSUM_SUPPLIER.get(); - log.debug("Closing: files: {}, bytes {}, raw hash {}", filesToProcess, filesTotalSize, hash); + log.debug("Closing: files: {}, bytes {}, raw hash {}", filesProcessed, filesTotalSize, hash); hasher.update(hash); - hasher.update(filesToProcess); + hasher.update(filesProcessed); hasher.update(filesTotalSize); return hasher.getValue(); diff --git a/src/main/java/net/szum123321/textile_backup/core/digest/Hash.java b/src/main/java/net/szum123321/textile_backup/core/digest/Hash.java index aa54578..8d67b83 100644 --- a/src/main/java/net/szum123321/textile_backup/core/digest/Hash.java +++ b/src/main/java/net/szum123321/textile_backup/core/digest/Hash.java @@ -19,9 +19,8 @@ package net.szum123321.textile_backup.core.digest; public interface Hash { - void update(byte b); - default void update(int b) { update((byte)b); } + void update(int b) ; void update(long b); diff --git a/src/main/java/net/szum123321/textile_backup/core/digest/HashingInputStream.java b/src/main/java/net/szum123321/textile_backup/core/digest/HashingInputStream.java index df9ef98..409efa1 100644 --- a/src/main/java/net/szum123321/textile_backup/core/digest/HashingInputStream.java +++ b/src/main/java/net/szum123321/textile_backup/core/digest/HashingInputStream.java @@ -38,8 +38,6 @@ import java.nio.file.Path; * That is what CountDownLatch does */ public class HashingInputStream extends FilterInputStream { - private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME); - private final Path path; private final Hash hasher = Globals.CHECKSUM_SUPPLIER.get(); private final FileTreeHashBuilder hashBuilder; diff --git a/src/main/java/net/szum123321/textile_backup/core/digest/HashingOutputStream.java b/src/main/java/net/szum123321/textile_backup/core/digest/HashingOutputStream.java index 3b293ba..46b04a5 100644 --- a/src/main/java/net/szum123321/textile_backup/core/digest/HashingOutputStream.java +++ b/src/main/java/net/szum123321/textile_backup/core/digest/HashingOutputStream.java @@ -41,7 +41,7 @@ public class HashingOutputStream extends FilterOutputStream { @Override public void write(int b) throws IOException { out.write(b); - hasher.update((byte)b); + hasher.update(b); } @Override diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index fbd649f..cbf3e57 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -40,7 +40,7 @@ "depends": { "fabricloader": ">=0.14.0", "fabric": "*", - "minecraft": "1.20-alpha.23.18.a", + "minecraft": "1.20-beta.1", "cloth-config2": "*", "java": ">=16" },