Commit f3dbb746 by eguven Committed by Oliver Woodman

Fix unnecessary rewrite of cache index file after CachedContentIndex.readFile()

Prevented readFile() setting "changed" boolean to true every time. It's set only if encryption key is set but the index file isn't encrypted.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=140714173
parent 836cefcd
...@@ -235,13 +235,17 @@ import javax.crypto.spec.SecretKeySpec; ...@@ -235,13 +235,17 @@ import javax.crypto.spec.SecretKeySpec;
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
input = new DataInputStream(new CipherInputStream(inputStream, cipher)); input = new DataInputStream(new CipherInputStream(inputStream, cipher));
} else {
if (cipher != null) {
changed = true; // Force index to be rewritten encrypted after read.
}
} }
int count = input.readInt(); int count = input.readInt();
int hashCode = 0; int hashCode = 0;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
CachedContent cachedContent = new CachedContent(input); CachedContent cachedContent = new CachedContent(input);
addNew(cachedContent); add(cachedContent);
hashCode += cachedContent.headerHashCode(); hashCode += cachedContent.headerHashCode();
} }
if (input.readInt() != hashCode) { if (input.readInt() != hashCode) {
...@@ -302,10 +306,14 @@ import javax.crypto.spec.SecretKeySpec; ...@@ -302,10 +306,14 @@ import javax.crypto.spec.SecretKeySpec;
} }
} }
/** Adds the given CachedContent to the index. */ private void add(CachedContent cachedContent) {
/*package*/ void addNew(CachedContent cachedContent) {
keyToContent.put(cachedContent.key, cachedContent); keyToContent.put(cachedContent.key, cachedContent);
idToKey.put(cachedContent.id, cachedContent.key); idToKey.put(cachedContent.id, cachedContent.key);
}
/** Adds the given CachedContent to the index. */
/*package*/ void addNew(CachedContent cachedContent) {
add(cachedContent);
changed = true; changed = true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment