Skip pack header bytes in DfsPackFile

The 12 bytes `PACK...` header is written in PackWriter before reading
CachedPack files. In DfsPackFile#copyPackBypassCache, the header was not
skipped when the first block is not in cache.

Change-Id: Ibbe2e564d36b79922a936657f286addb1044d237
Signed-off-by: Zhen Chen <czhen@google.com>
This commit is contained in:
Zhen Chen 2017-01-13 22:02:37 -08:00
parent 55c629a9f3
commit d6b354f60f
1 changed files with 10 additions and 1 deletions

View File

@ -499,6 +499,7 @@ private long copyPackBypassCache(PackOutputStream out, DfsReader ctx)
rc.setReadAheadBytes(ctx.getOptions().getStreamPackBufferSize());
long position = 12;
long remaining = length - (12 + 20);
boolean packHeadSkipped = false;
while (0 < remaining) {
DfsBlock b = cache.get(key, alignToBlock(position));
if (b != null) {
@ -508,6 +509,7 @@ private long copyPackBypassCache(PackOutputStream out, DfsReader ctx)
position += n;
remaining -= n;
rc.position(position);
packHeadSkipped = true;
continue;
}
@ -517,7 +519,14 @@ private long copyPackBypassCache(PackOutputStream out, DfsReader ctx)
throw packfileIsTruncated();
else if (n > remaining)
n = (int) remaining;
out.write(buf.array(), 0, n);
if (!packHeadSkipped) {
// Need skip the 'PACK' header for the first read
out.write(buf.array(), 12, n - 12);
packHeadSkipped = true;
} else {
out.write(buf.array(), 0, n);
}
position += n;
remaining -= n;
}