{"thread":{"id":"15042","subject":"[JGIT PATCH] On error in DirCache.lock, do not leave the index locked.","startedAt":"2008-08-16T21:36:27Z","lastAt":"2008-08-18T05:46:00Z","messageCount":2,"participants":["John J. Franey","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"87390","messageId":"1218922587.30527.2.camel@isidore.myhome.westell.com","threadId":"15042","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-16T21:36:27Z","receivedAt":"2008-08-16T21:36:27Z","isPatch":true,"sender":{"key":"jjfraney@gmail.com","avatar":null},"body":"After 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 retry: My first email for this had mail header in mail body - sorry.\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"},{"id":"87514","messageId":"20080818054600.GA7376@spearce.org","threadId":"15042","inReplyTo":"1218922587.30527.2.camel@isidore.myhome.westell.com","subject":"Re: [JGIT PATCH] On error in DirCache.lock, do not leave the index locked.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-08-18T05:46:00Z","receivedAt":"2008-08-18T05:46:00Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"\"John J. Franey\" <jjfraney@gmail.com> wrote:\n> After using C git on the same repository, the jgit cache read\n> threw an EOFException, and left the index lock file.\n> The repository is still valid according to C git, but\n> unreachable by C git because it honors the lock file\n> left behind by jgit.\n\nUrgh.  Thanks for the patch.\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\nIf you can reproduce it, I'd like to see a copy of the index file\nif that is possible.  I was pretty certain DirCache honors the\nindex file format properly, but a short read of a block suggests\nwe misread a length field somewhere.\n \n-- \nShawn.\n"}]}