YYYYEEEEEEEEEEEEEEEEEEe I finally debugged the hash!!!!!

The problem was due to an error in usage o FileTreeHashBuilder during unpacking.
This commit is contained in:
Szum123321 2023-05-10 23:32:54 +02:00
parent fe9f9f3e0d
commit b9af3b3777
9 changed files with 15 additions and 27 deletions

View File

@ -1,18 +1,18 @@
# Done to increase the memory available to gradle. # Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
minecraft_version=23w18a minecraft_version=1.20-pre1
yarn_mappings=23w18a+build.5 yarn_mappings=1.20-pre1+build.2
loader_version=0.14.19 loader_version=0.14.19
#Fabric api #Fabric api
fabric_version=0.80.1+1.20 fabric_version=0.80.2+1.20
#Cloth Config #Cloth Config
cloth_version=11.0.97 cloth_version=11.0.97
#ModMenu #ModMenu
modmenu_version=6.2.2 modmenu_version=7.0.0-beta.2
databreaker_version=0.2.10 databreaker_version=0.2.10

View File

@ -60,11 +60,6 @@ public class TextileBackup implements ModInitializer {
log.info("Starting Textile Backup {} by Szum123321", Globals.INSTANCE.getCombinedVersionString()); 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)); ConfigHelper.updateInstance(AutoConfig.register(ConfigPOJO.class, JanksonConfigSerializer::new));
ServerTickEvents.END_SERVER_TICK.register(BackupScheduler::tick); ServerTickEvents.END_SERVER_TICK.register(BackupScheduler::tick);

View File

@ -115,9 +115,7 @@ public class Utilities {
} }
public static boolean isBlacklisted(Path path) { public static boolean isBlacklisted(Path path) {
if(isWindows()) { //hotfix! if (path.getFileName().equals("session.lock")) return true;
if (path.getFileName().toString().equals("session.lock")) return true;
}
if(path.getFileName().endsWith(CompressionStatus.DATA_FILENAME)) return true; if(path.getFileName().endsWith(CompressionStatus.DATA_FILENAME)) return true;

View File

@ -38,8 +38,8 @@ public class BalticHash implements Hash {
protected final ByteBuffer buffer = ByteBuffer.wrap(_byte_buffer).order(ByteOrder.LITTLE_ENDIAN); protected final ByteBuffer buffer = ByteBuffer.wrap(_byte_buffer).order(ByteOrder.LITTLE_ENDIAN);
protected long hashed_data_length = 0; protected long hashed_data_length = 0;
public void update(byte b) { public void update(int b) {
buffer.put(b); buffer.put((byte)b);
hashed_data_length += 1; hashed_data_length += 1;
if (buffer.position() >= buffer_limit) round(); if (buffer.position() >= buffer_limit) round();
} }

View File

@ -36,13 +36,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class FileTreeHashBuilder { public class FileTreeHashBuilder {
private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME); private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME);
private final Object lock = new Object(); private final Object lock = new Object();
private long hash = 0, filesToProcess, filesTotalSize = 0; private long hash = 0, filesProcessed = 0, filesTotalSize = 0;
private final AtomicBoolean closed = new AtomicBoolean(false);
private final CountDownLatch latch; private final CountDownLatch latch;
public FileTreeHashBuilder(int filesToProcess) { public FileTreeHashBuilder(int filesToProcess) {
this.filesToProcess = filesToProcess;
latch = new CountDownLatch(filesToProcess); latch = new CountDownLatch(filesToProcess);
} }
@ -55,23 +53,23 @@ public class FileTreeHashBuilder {
synchronized (lock) { synchronized (lock) {
this.hash ^= newHash; this.hash ^= newHash;
filesToProcess--;
filesTotalSize += size; filesTotalSize += size;
filesProcessed++;
} }
} }
public int getRemaining() { return (int) latch.getCount(); } 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(); long leftover = latch.getCount();
if(lock) latch.await(); if(lock) latch.await();
else if(leftover != 0) log.warn("Finishing with {} files unprocessed!", leftover); else if(leftover != 0) log.warn("Finishing with {} files unprocessed!", leftover);
var hasher = Globals.CHECKSUM_SUPPLIER.get(); 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(hash);
hasher.update(filesToProcess); hasher.update(filesProcessed);
hasher.update(filesTotalSize); hasher.update(filesTotalSize);
return hasher.getValue(); return hasher.getValue();

View File

@ -19,9 +19,8 @@
package net.szum123321.textile_backup.core.digest; package net.szum123321.textile_backup.core.digest;
public interface Hash { public interface Hash {
void update(byte b);
default void update(int b) { update((byte)b); } void update(int b) ;
void update(long b); void update(long b);

View File

@ -38,8 +38,6 @@ import java.nio.file.Path;
* That is what CountDownLatch does * That is what CountDownLatch does
*/ */
public class HashingInputStream extends FilterInputStream { public class HashingInputStream extends FilterInputStream {
private final static TextileLogger log = new TextileLogger(TextileBackup.MOD_NAME);
private final Path path; private final Path path;
private final Hash hasher = Globals.CHECKSUM_SUPPLIER.get(); private final Hash hasher = Globals.CHECKSUM_SUPPLIER.get();
private final FileTreeHashBuilder hashBuilder; private final FileTreeHashBuilder hashBuilder;

View File

@ -41,7 +41,7 @@ public class HashingOutputStream extends FilterOutputStream {
@Override @Override
public void write(int b) throws IOException { public void write(int b) throws IOException {
out.write(b); out.write(b);
hasher.update((byte)b); hasher.update(b);
} }
@Override @Override

View File

@ -40,7 +40,7 @@
"depends": { "depends": {
"fabricloader": ">=0.14.0", "fabricloader": ">=0.14.0",
"fabric": "*", "fabric": "*",
"minecraft": "1.20-alpha.23.18.a", "minecraft": "1.20-beta.1",
"cloth-config2": "*", "cloth-config2": "*",
"java": ">=16" "java": ">=16"
}, },