Ensure that a PackFile instance stays invalid when overwritten
commit652d889d6a54f1951547cf6fbac18dcbed757d5e
authorShawn O. Pearce <spearce@spearce.org>
Mon, 4 May 2009 19:30:45 +0000 (4 12:30 -0700)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Mon, 4 May 2009 22:42:15 +0000 (5 00:42 +0200)
treefb94ddecc1450450d47bd9bcf5f88445e3d0d800
parente2c9d6f70baeeb0fbad02c9f8db9f904d91f286f
Ensure that a PackFile instance stays invalid when overwritten

If a PackFile gets overwritten after we read its pack-*.idx we
throw a PackMismatchException and then close the PackFile, which
discards the index.  At this point the PackFile instance is dead
and must be discarded by the GC, as it is used as part of the key
in the WindowCache and the UnpackedObjectCache.

There is however a subtle race condition here.  If the PackFile is
opened again after the PackMismatchException is thrown we load the
new index file into memory, possibly seeing the footer in the index
match the footer in the pack, and believing that the file is valid.
This can mean that stale windows that haven't yet expired out of the
WindowCache suddenly become valid again, even though they contain
data from the old version of the pack.

By caching the pack signature the very first time we open it we
can more reliably detect this overwrite race condition and keep
the PackFile instance invalid.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.spearce.jgit/src/org/spearce/jgit/errors/PackInvalidException.java [new file with mode: 0644]
org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java