[JGIT PATCH] On error in DirCache.lock, do not leave the index locked.

Subsystems: the rest

DORMANTno replies

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

[JGIT PATCH] On error in DirCache.lock, do not leave the index locked.

From: John J. Franey <hidden>
Date: 2016-06-15 22:45:10

After using C git on the same repository, the jgit cache read
threw an EOFException, and left the index lock file.
The repository is still valid according to C git, but
unreachable by C git because it honors the lock file
left behind by jgit.

Signed-off-by: John J. Franey <redacted>
---
 retry: My first email for this had mail header in mail body - sorry.

 Hi, hope this helps.

 The reason for the EOFException is beyond me right now.  It
 reported "Short read of block."  However, I'm pretty sure
 leaving the lock file in place is an error.

 Regards,
 John

 .../src/org/spearce/jgit/dircache/DirCache.java    |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 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 280149a..c52d98b 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
@@ -158,7 +158,8 @@ public static DirCache read(final Repository db)
 	 * <p>
 	 * The new index will be locked and then read before it is returned to the
 	 * caller. Read failures are reported as exceptions and therefore prevent
-	 * the method from returning a partially populated index.
+	 * the method from returning a partially populated index.  On read failure,
+	 * the lock is released.
 	 *
 	 * @param indexLocation
 	 *            location of the index file on disk.
@@ -176,7 +177,20 @@ public static DirCache lock(final File indexLocation)
 		final DirCache c = new DirCache(indexLocation);
 		if (!c.lock())
 			throw new IOException("Cannot lock " + indexLocation);
-		c.read();
+		
+		try {
+			c.read();
+		} catch(IOException e) {
+			c.unlock();
+			throw e;
+		} catch(RuntimeException e) {
+			c.unlock();
+			throw e;
+		} catch(Error e) {
+			c.unlock();
+			throw e;
+		}
+		
 		return c;
 	}
 
-- 
1.6.0.rc1.71.gfba5

Re: [JGIT PATCH] On error in DirCache.lock, do not leave the index locked.

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:45:10

"John J. Franey" [off-list ref] wrote:
After using C git on the same repository, the jgit cache read
threw an EOFException, and left the index lock file.
The repository is still valid according to C git, but
unreachable by C git because it honors the lock file
left behind by jgit.
Urgh.  Thanks for the patch.
 
 The reason for the EOFException is beyond me right now.  It
 reported "Short read of block."  However, I'm pretty sure
 leaving the lock file in place is an error.
If you can reproduce it, I'd like to see a copy of the index file
if that is possible.  I was pretty certain DirCache honors the
index file format properly, but a short read of a block suggests
we misread a length field somewhere.
 
-- 
Shawn.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help