git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
JFJohn J. Franey <jjfraney@gmail.com>
Date
Aug 16, 2008, 21:36 UTC
Message-ID
<1218922587.30527.2.camel@isidore.myhome.westell.com>

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 <jjfraney@gmail.com>
---
 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
Next: Shawn O. Pearce
Message 1 of 2 in “On error in DirCache.lock, do not leave the index locked.”
  1. On error in DirCache.lock, do not leave the index locked.John J. Franey, Aug 16, 2008
  2. Shawn O. PearceAug 18, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.