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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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




--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux