{"thread":{"id":"15038","subject":"[JGIT PATCH] On error in DirCache.lock, do not leave the index locked.","startedAt":"2008-08-16T20:29:05Z","lastAt":"2008-08-16T20:29:05Z","messageCount":1,"participants":["John J. Franey"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"87386","messageId":"1218918545.27000.22.camel@isidore.myhome.westell.com","threadId":"15038","inReplyTo":null,"subject":"[JGIT PATCH] On error in DirCache.lock, do not leave the index locked.","fromName":"John J. Franey","fromEmail":"jjfraney@gmail.com","sentAt":"2008-08-16T20:29:05Z","receivedAt":"2008-08-16T20:29:05Z","isPatch":true,"sender":{"key":"jjfraney@gmail.com","avatar":null},"body":"\n>From 557280ecdcb4729c481ff6f1817bb277f11caec7 Mon Sep 17 00:00:00 2001\nFrom: John J. Franey <jjfraney@gmail.com>\nDate: Sat, 16 Aug 2008 15:32:48 -0400\nSubject: [PATCH] On error in DirCache.lock, do not leave the index locked.\n\nAfter using C git on the same repository, the jgit cache read\nthrew an EOFException, and left the index lock file.\nThe repository is still valid according to C git, but\nunreachable by C git because it honors the lock file\nleft behind by jgit.\n\nSigned-off-by: John J. Franey <jjfraney@gmail.com>\n---\n Hi, hope this helps.\n\n The reason for the EOFException is beyond me right now.  It\n reported \"Short read of block.\"  However, I'm pretty sure\n leaving the lock file in place is an error.\n\n Regards,\n John\n\n .../src/org/spearce/jgit/dircache/DirCache.java    |   18 ++++++++++++++++--\n 1 files changed, 16 insertions(+), 2 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java\nindex 280149a..c52d98b 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java\n@@ -158,7 +158,8 @@ public static DirCache read(final Repository db)\n \t * <p>\n \t * The new index will be locked and then read before it is returned to the\n \t * caller. Read failures are reported as exceptions and therefore prevent\n-\t * the method from returning a partially populated index.\n+\t * the method from returning a partially populated index.  On read failure,\n+\t * the lock is released.\n \t *\n \t * @param indexLocation\n \t *            location of the index file on disk.\n@@ -176,7 +177,20 @@ public static DirCache lock(final File indexLocation)\n \t\tfinal DirCache c = new DirCache(indexLocation);\n \t\tif (!c.lock())\n \t\t\tthrow new IOException(\"Cannot lock \" + indexLocation);\n-\t\tc.read();\n+\t\t\n+\t\ttry {\n+\t\t\tc.read();\n+\t\t} catch(IOException e) {\n+\t\t\tc.unlock();\n+\t\t\tthrow e;\n+\t\t} catch(RuntimeException e) {\n+\t\t\tc.unlock();\n+\t\t\tthrow e;\n+\t\t} catch(Error e) {\n+\t\t\tc.unlock();\n+\t\t\tthrow e;\n+\t\t}\n+\t\t\n \t\treturn c;\n \t}\n \n-- \n1.6.0.rc1.71.gfba5\n"}]}