From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: spearce@spearce.org
Cc: git@vger.kernel.org, Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [EGIT PATCH] Improve end-of-file detection in DirCache
Date: Wed, 8 Apr 2009 17:50:52 +0200 [thread overview]
Message-ID: <1239205852-28138-1-git-send-email-robin.rosenberg@dewire.com> (raw)
When reading from an BufferInputStream attached to a
FileInputStream the available() method seems to return
the number of unread bytes in the buffer plus the unread
number of bytes in the file.
There is no guarantee for this behaviour so this quick fix
might not be as stable as we would wish.
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
http://code.google.com/p/egit/issues/detail?id=66
---
.../src/org/spearce/jgit/dircache/DirCache.java | 16 ++++++++++------
1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
index 8eb4022..657762e 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
@@ -45,7 +45,6 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.util.Comparator;
@@ -344,8 +343,6 @@ public void clear() {
private void readFrom(final FileInputStream inStream) throws IOException,
CorruptObjectException {
- final FileChannel fd = inStream.getChannel();
- final long sizeOnDisk = fd.size();
final BufferedInputStream in = new BufferedInputStream(inStream);
// Read the index header and verify we understand it.
@@ -369,9 +366,16 @@ private void readFrom(final FileInputStream inStream) throws IOException,
sortedEntries[i] = new DirCacheEntry(infos, i * INFO_LEN, in);
lastModified = liveFile.lastModified();
- // After the file entries are index extensions.
- //
- while (fd.position() - in.available() < sizeOnDisk - 20) {
+ /*
+ * InputStream.available() on file input streams seems to return the
+ * rest of the file i.e. buffer size + unread file on disk. There is no
+ * guarantee for this so we need to fix this or we may miss extensions
+ * when reading the index in a few races cases.
+ *
+ * That is currently no disaster though.
+ */
+ while (in.available() > 20) {
+ // After the file entries are index extensions.
NB.readFully(in, hdr, 0, 8);
switch (NB.decodeInt32(hdr, 0)) {
case EXT_TREE: {
--
1.6.2.2.446.gfbdc0
next reply other threads:[~2009-04-08 15:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-08 15:50 Robin Rosenberg [this message]
2009-04-09 15:28 ` [JGIT PATCH 1/2] Improve end-of-file detection in DirCache Shawn O. Pearce
2009-04-09 15:28 ` [JGIT PATCH 2/2] Validate the DIRC footer during read Shawn O. Pearce
2009-04-10 2:35 ` [JGIT PATCH 1/2] Improve end-of-file detection in DirCache Robin Rosenberg
2009-04-13 11:53 ` Robin Rosenberg
2009-04-13 15:42 ` Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1239205852-28138-1-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).