]> source.dussan.org Git - jgit.git/commitdiff
Provide more details in exceptions thrown when packfile is invalid 45/41545/3
authorMatthias Sohn <matthias.sohn@sap.com>
Tue, 10 Feb 2015 17:23:14 +0000 (18:23 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 17 Feb 2015 13:13:22 +0000 (14:13 +0100)
Mention packfile path in exceptions thrown when we detect that a
packfile is invalid and make excplicit that corrupt packs are removed
from the pack list.

Change-Id: I454ada5f8e69307d3f34d1c1b8f3cb87607ddf35
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ProtocolErrorTest.java
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java

index 2823b34b1f3ce93edc8b882e7faef66f55c03713..68c5a3a439591fe79f5440ec6f01fe0a916c8f64 100644 (file)
@@ -162,7 +162,7 @@ public class ProtocolErrorTest extends HttpTestCase {
                        try {
                                PacketLineIn pckin = new PacketLineIn(rawin);
                                assertEquals("unpack error "
-                                               + JGitText.get().packfileIsTruncated,
+                                               + JGitText.get().packfileIsTruncatedNoParam,
                                                pckin.readString());
                                assertEquals("ng refs/objects/A n/a (unpacker error)",
                                                pckin.readString());
index efe61052b0134269e714e1388a2cf93a24ee1f37..66b14bb7a36f372f9b87eda67c65701967414d20 100644 (file)
@@ -146,7 +146,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
+corruptPack=Pack file {0} is corrupt, removing it from pack list
 createBranchFailedUnknownReason=Create branch failed for unknown reason
 createBranchUnexpectedResult=Create branch returned unexpected result {0}
 createNewFileFailed=Could not create new file {0}
@@ -381,14 +381,15 @@ openFilesMustBeAtLeast1=Open files must be >= 1
 openingConnection=Opening connection
 operationCanceled=Operation {0} was canceled
 outputHasAlreadyBeenStarted=Output has already been started.
-packChecksumMismatch=Pack checksum mismatch
+packChecksumMismatch=Pack checksum mismatch detected for pack file {0}
 packCorruptedWhileWritingToFilesystem=Pack corrupted while writing to filesystem
 packDoesNotMatchIndex=Pack {0} does not match index
 packetSizeMustBeAtLeast=packet size {0} must be >= {1}
 packetSizeMustBeAtMost=packet size {0} must be <= {1}
 packfileCorruptionDetected=Packfile corruption detected: {0}
 packFileInvalid=Pack file invalid: {0}
-packfileIsTruncated=Packfile is truncated.
+packfileIsTruncated=Packfile {0} is truncated.
+packfileIsTruncatedNoParam=Packfile is truncated.
 packHasUnresolvedDeltas=pack has unresolved deltas
 packingCancelledDuringObjectsWriting=Packing cancelled during objects writing
 packObjectCountMismatch=Pack object count mismatch: pack {0} index {1}: {2}
index 8c81c95134b71f6ada0eabd16aa1fc808fbfc4e1..0300af197f39d76eee4ba98a9346e2a135774881 100644 (file)
@@ -448,6 +448,7 @@ public class JGitText extends TranslationBundle {
        /***/ public String packfileCorruptionDetected;
        /***/ public String packFileInvalid;
        /***/ public String packfileIsTruncated;
+       /***/ public String packfileIsTruncatedNoParam;
        /***/ public String packHasUnresolvedDeltas;
        /***/ public String packingCancelledDuringObjectsWriting;
        /***/ public String packObjectCountMismatch;
index 7c4776ea0673a1e6505e289a8c8e68ee16dbbc20..d5e1a582ce5af3e3958ad2c43f3633c6f4792d8f 100644 (file)
@@ -199,7 +199,7 @@ public final class DfsPackFile {
                return key.cachedSize.get();
        }
 
-       private String getPackName() {
+       String getPackName() {
                return packDesc.getFileName(PACK);
        }
 
index 37dbc7ea7e1e361e075ae71126c0fe49a1c27b2a..4cf7cbefced10e4102c7da1a5cdf6a2a6e886747 100644 (file)
@@ -556,7 +556,8 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
                        pin(pack, 0);
                        if (block.copy(0, buf, 0, 12) != 12) {
                                pack.setInvalid();
-                               throw new IOException(JGitText.get().packfileIsTruncated);
+                               throw new IOException(MessageFormat.format(
+                                               JGitText.get().packfileIsTruncated, pack.getPackName()));
                        }
                        md.update(buf, 0, 12);
                }
@@ -580,7 +581,8 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
                        pin(pack, position);
                        if (block.copy(position, buf, 0, 20) != 20) {
                                pack.setInvalid();
-                               throw new IOException(JGitText.get().packfileIsTruncated);
+                               throw new IOException(MessageFormat.format(
+                                               JGitText.get().packfileIsTruncated, pack.getPackName()));
                        }
                        if (!Arrays.equals(actHash, buf)) {
                                pack.setInvalid();
index 306a0d3896e71d0c22f13fedb2fb49d523b328a5..eb2293874f71519bb595dc0f559c2262179d2a91 100644 (file)
@@ -169,11 +169,13 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
                        try {
                                final PackIndex idx = PackIndex.open(extFile(INDEX));
 
-                               if (packChecksum == null)
+                               if (packChecksum == null) {
                                        packChecksum = idx.packChecksum;
-                               else if (!Arrays.equals(packChecksum, idx.packChecksum))
-                                       throw new PackMismatchException(JGitText.get().packChecksumMismatch);
-
+                               } else if (!Arrays.equals(packChecksum, idx.packChecksum)) {
+                                       throw new PackMismatchException(MessageFormat.format(
+                                                       JGitText.get().packChecksumMismatch,
+                                                       packFile.getPath()));
+                               }
                                loadedIdx = idx;
                        } catch (IOException e) {
                                invalid = true;
index a0a4c952fce64ffe77d16b22622435b07d4896b1..85c3c74255d0d34824f745c1ba7668f57f0b4a59 100644 (file)
@@ -246,7 +246,9 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs {
                        pin(pack, 0);
                        if (window.copy(0, buf, 0, 12) != 12) {
                                pack.setInvalid();
-                               throw new IOException(JGitText.get().packfileIsTruncated);
+                               throw new IOException(MessageFormat.format(
+                                               JGitText.get().packfileIsTruncated, pack.getPackFile()
+                                                               .getPath()));
                        }
                        md.update(buf, 0, 12);
                }
@@ -270,7 +272,9 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs {
                        pin(pack, position);
                        if (window.copy(position, buf, 0, 20) != 20) {
                                pack.setInvalid();
-                               throw new IOException(JGitText.get().packfileIsTruncated);
+                               throw new IOException(MessageFormat.format(
+                                               JGitText.get().packfileIsTruncated, pack.getPackFile()
+                                                               .getPath()));
                        }
                        if (!Arrays.equals(actHash, buf)) {
                                pack.setInvalid();
index 633554a96fa12b348ba093fbe33dd6ced1d207a2..5b54891cd16a1c6a390e5b5a406ec4e8c4a05a7e 100644 (file)
@@ -1135,7 +1135,8 @@ public abstract class PackParser {
                                break;
                        }
                        if (next <= 0)
-                               throw new EOFException(JGitText.get().packfileIsTruncated);
+                               throw new EOFException(
+                                               JGitText.get().packfileIsTruncatedNoParam);
                        bAvail += next;
                }
                return bOffset;