diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index a753188e8..55cf3ea71 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -145,6 +145,7 @@ couldNotRenameTemporaryIndexFileToIndex=Could not rename temporary index file to couldNotURLEncodeToUTF8=Could not URL encode to UTF-8 couldNotWriteFile=Could not write file {0} countingObjects=Counting objects +corruptPack=Pack file {0} is corrupt createBranchFailedUnknownReason=Create branch failed for unknown reason createBranchUnexpectedResult=Create branch returned unexpected result {0} createNewFileFailed=Could not create new file {0} @@ -207,6 +208,7 @@ exceptionCaughtDuringExecutionOfRmCommand=Exception caught during execution of r exceptionCaughtDuringExecutionOfTagCommand=Exception caught during execution of tag command exceptionOccurredDuringAddingOfOptionToALogCommand=Exception occurred during adding of {0} as option to a Log command exceptionOccurredDuringReadingOfGIT_DIR=Exception occurred during reading of $GIT_DIR/{0}. {1} +exceptionWhileReadingPack=ERROR: Exception caught while accessing pack file {0}, the pack file might be corrupt expectedACKNAKFoundEOF=Expected ACK/NAK, found EOF expectedACKNAKGot=Expected ACK/NAK, got: {0} expectedBooleanStringValue=Expected boolean string value diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index 65272fb0b..fd38dc149 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -190,6 +190,7 @@ public class JGitText extends TranslationBundle { /***/ public String corruptObjectNotree; /***/ public String corruptObjectNoType; /***/ public String corruptObjectPackfileChecksumIncorrect; + /***/ public String corruptPack; /***/ public String couldNotCheckOutBecauseOfConflicts; /***/ public String couldNotDeleteLockFileShouldNotHappen; /***/ public String couldNotDeleteTemporaryIndexFileShouldNotHappen; @@ -266,6 +267,7 @@ public class JGitText extends TranslationBundle { /***/ public String exceptionCaughtDuringExecutionOfTagCommand; /***/ public String exceptionOccurredDuringAddingOfOptionToALogCommand; /***/ public String exceptionOccurredDuringReadingOfGIT_DIR; + /***/ public String exceptionWhileReadingPack; /***/ public String expectedACKNAKFoundEOF; /***/ public String expectedACKNAKGot; /***/ public String expectedBooleanStringValue; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java index 58276051e..76fadefe5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java @@ -52,6 +52,8 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; @@ -64,6 +66,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; +import org.eclipse.jgit.errors.CorruptObjectException; +import org.eclipse.jgit.errors.PackInvalidException; import org.eclipse.jgit.errors.PackMismatchException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.storage.pack.ObjectToPack; @@ -328,9 +332,7 @@ public class ObjectDirectory extends FileObjectDatabase { try { p.resolve(matches, id, RESOLVE_ABBREV_LIMIT); } catch (IOException e) { - // Assume the pack is corrupted. - // - removePack(p); + handlePackError(e, p); } if (matches.size() > RESOLVE_ABBREV_LIMIT) return; @@ -417,8 +419,7 @@ public class ObjectDirectory extends FileObjectDatabase { if (searchPacksAgain(pList)) continue SEARCH; } catch (IOException e) { - // Assume the pack is corrupted. - removePack(p); + handlePackError(e, p); } } break SEARCH; @@ -498,8 +499,7 @@ public class ObjectDirectory extends FileObjectDatabase { if (searchPacksAgain(pList)) continue SEARCH; } catch (IOException e) { - // Assume the pack is corrupted. - removePack(p); + handlePackError(e, p); } } break SEARCH; @@ -540,9 +540,7 @@ public class ObjectDirectory extends FileObjectDatabase { pList = scanPacks(pList); continue SEARCH; } catch (IOException e) { - // Assume the pack is corrupted. - // - removePack(p); + handlePackError(e, p); } } break SEARCH; @@ -552,6 +550,28 @@ public class ObjectDirectory extends FileObjectDatabase { h.db.selectObjectRepresentation(packer, otp, curs); } + private void handlePackError(IOException e, PackFile p) { + String tmpl; + if ((e instanceof CorruptObjectException) + || (e instanceof PackInvalidException)) { + tmpl = JGitText.get().corruptPack; + // Assume the pack is corrupted, and remove it from the list. + removePack(p); + } else { + tmpl = JGitText.get().exceptionWhileReadingPack; + // Don't remove the pack from the list, as the error may be + // transient. + } + StringBuilder buf = new StringBuilder(MessageFormat.format(tmpl, + p.getPackFile().getAbsolutePath())); + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw)); + buf.append('\n'); + buf.append(sw.toString()); + // TODO instead of syserr we should use a logging framework + System.err.println(buf.toString()); + } + @Override InsertLooseObjectResult insertUnpackedObject(File tmp, ObjectId id, boolean createDuplicate) throws IOException {