cache: assume archive data we don't decompress contains no revision. The downloaded data does not.
This commit is contained in:
@@ -153,8 +153,9 @@ public class Archive
|
||||
logger.warn("whirlpool mismatch for archive {}", this);
|
||||
}
|
||||
|
||||
if (this.getRevision() != res.revision)
|
||||
if (res.revision != -1 && this.getRevision() != res.revision)
|
||||
{
|
||||
// compressed data doesn't always include a revision, but check it if it does
|
||||
logger.warn("revision mismatch for archive {}", this);
|
||||
}
|
||||
|
||||
|
||||
@@ -377,7 +377,7 @@ public class DataFile implements Closeable
|
||||
DataFileReadResult res = new DataFileReadResult();
|
||||
res.data = data;
|
||||
res.revision = revision;
|
||||
int length = revision != -1 ? b.length - 2 : b.length;;
|
||||
int length = revision != -1 ? b.length - 2 : b.length;
|
||||
res.crc = crc32.getHash();
|
||||
res.whirlpool = Whirlpool.getHash(b, length);
|
||||
res.compression = compression;
|
||||
|
||||
@@ -211,7 +211,7 @@ public class Index implements Closeable
|
||||
|
||||
public void save() throws IOException
|
||||
{
|
||||
saveFiles();
|
||||
saveArchives();
|
||||
|
||||
byte[] data = this.writeIndexData();
|
||||
|
||||
@@ -348,26 +348,29 @@ public class Index implements Closeable
|
||||
}
|
||||
}
|
||||
|
||||
public void saveFiles() throws IOException
|
||||
public void saveArchives() throws IOException
|
||||
{
|
||||
for (Archive a : archives)
|
||||
{
|
||||
assert this.index.getIndexFileId() == this.id;
|
||||
DataFile data = store.getData();
|
||||
|
||||
int rev; // used for determining what part of compressedData to crc
|
||||
byte[] compressedData;
|
||||
|
||||
if (a.getData() != null)
|
||||
{
|
||||
compressedData = a.getData(); // data was never decompressed or loaded
|
||||
rev = -1; // assume that this data has no revision?
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] fileData = a.saveContents();
|
||||
rev = a.getRevision();
|
||||
compressedData = DataFile.compress(fileData, a.getCompression(), a.getRevision(), null);
|
||||
}
|
||||
|
||||
DataFileWriteResult res = data.write(this.id, a.getArchiveId(), compressedData, a.getRevision());
|
||||
DataFileWriteResult res = data.write(this.id, a.getArchiveId(), compressedData, rev);
|
||||
this.index.write(new IndexEntry(this.index, a.getArchiveId(), res.sector, res.compressedLength));
|
||||
|
||||
logger.trace("Saved archive {}/{} at sector {}, compressed length {}", this.getId(), a.getArchiveId(), res.sector, res.compressedLength);
|
||||
|
||||
@@ -26,7 +26,6 @@ package net.runelite.cache.fs;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import net.runelite.cache.StoreLocation;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
@@ -56,6 +55,8 @@ public class DataFileTest
|
||||
byte[] buf = res2.data;
|
||||
String str = new String(buf);
|
||||
Assert.assertEquals("test", str);
|
||||
|
||||
Assert.assertEquals(res.crc, res2.crc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user