cache: assume archive data we don't decompress contains no revision. The downloaded data does not.

This commit is contained in:
Adam
2017-03-11 23:15:41 -05:00
parent 9170c41856
commit 963d82c903
4 changed files with 11 additions and 6 deletions

View File

@@ -153,8 +153,9 @@ public class Archive
logger.warn("whirlpool mismatch for archive {}", this); 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); logger.warn("revision mismatch for archive {}", this);
} }

View File

@@ -377,7 +377,7 @@ public class DataFile implements Closeable
DataFileReadResult res = new DataFileReadResult(); DataFileReadResult res = new DataFileReadResult();
res.data = data; res.data = data;
res.revision = revision; 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.crc = crc32.getHash();
res.whirlpool = Whirlpool.getHash(b, length); res.whirlpool = Whirlpool.getHash(b, length);
res.compression = compression; res.compression = compression;

View File

@@ -211,7 +211,7 @@ public class Index implements Closeable
public void save() throws IOException public void save() throws IOException
{ {
saveFiles(); saveArchives();
byte[] data = this.writeIndexData(); 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) for (Archive a : archives)
{ {
assert this.index.getIndexFileId() == this.id; assert this.index.getIndexFileId() == this.id;
DataFile data = store.getData(); DataFile data = store.getData();
int rev; // used for determining what part of compressedData to crc
byte[] compressedData; byte[] compressedData;
if (a.getData() != null) if (a.getData() != null)
{ {
compressedData = a.getData(); // data was never decompressed or loaded compressedData = a.getData(); // data was never decompressed or loaded
rev = -1; // assume that this data has no revision?
} }
else else
{ {
byte[] fileData = a.saveContents(); byte[] fileData = a.saveContents();
rev = a.getRevision();
compressedData = DataFile.compress(fileData, a.getCompression(), a.getRevision(), null); 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)); 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); logger.trace("Saved archive {}/{} at sector {}, compressed length {}", this.getId(), a.getArchiveId(), res.sector, res.compressedLength);

View File

@@ -26,7 +26,6 @@ package net.runelite.cache.fs;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer;
import net.runelite.cache.StoreLocation; import net.runelite.cache.StoreLocation;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
@@ -56,6 +55,8 @@ public class DataFileTest
byte[] buf = res2.data; byte[] buf = res2.data;
String str = new String(buf); String str = new String(buf);
Assert.assertEquals("test", str); Assert.assertEquals("test", str);
Assert.assertEquals(res.crc, res2.crc);
} }
} }