@ -52,6 +52,8 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException ;
import java.io.FileNotFoundException ;
import java.io.FileReader ;
import java.io.FileReader ;
import java.io.IOException ;
import java.io.IOException ;
import java.io.PrintWriter ;
import java.io.StringWriter ;
import java.text.MessageFormat ;
import java.text.MessageFormat ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Arrays ;
@ -64,6 +66,8 @@ import java.util.Map;
import java.util.Set ;
import java.util.Set ;
import java.util.concurrent.atomic.AtomicReference ;
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.errors.PackMismatchException ;
import org.eclipse.jgit.internal.JGitText ;
import org.eclipse.jgit.internal.JGitText ;
import org.eclipse.jgit.internal.storage.pack.ObjectToPack ;
import org.eclipse.jgit.internal.storage.pack.ObjectToPack ;
@ -328,9 +332,7 @@ public class ObjectDirectory extends FileObjectDatabase {
try {
try {
p . resolve ( matches , id , RESOLVE_ABBREV_LIMIT ) ;
p . resolve ( matches , id , RESOLVE_ABBREV_LIMIT ) ;
} catch ( IOException e ) {
} catch ( IOException e ) {
// Assume the pack is corrupted.
handlePackError ( e , p ) ;
//
removePack ( p ) ;
}
}
if ( matches . size ( ) > RESOLVE_ABBREV_LIMIT )
if ( matches . size ( ) > RESOLVE_ABBREV_LIMIT )
return ;
return ;
@ -417,8 +419,7 @@ public class ObjectDirectory extends FileObjectDatabase {
if ( searchPacksAgain ( pList ) )
if ( searchPacksAgain ( pList ) )
continue SEARCH ;
continue SEARCH ;
} catch ( IOException e ) {
} catch ( IOException e ) {
// Assume the pack is corrupted.
handlePackError ( e , p ) ;
removePack ( p ) ;
}
}
}
}
break SEARCH ;
break SEARCH ;
@ -498,8 +499,7 @@ public class ObjectDirectory extends FileObjectDatabase {
if ( searchPacksAgain ( pList ) )
if ( searchPacksAgain ( pList ) )
continue SEARCH ;
continue SEARCH ;
} catch ( IOException e ) {
} catch ( IOException e ) {
// Assume the pack is corrupted.
handlePackError ( e , p ) ;
removePack ( p ) ;
}
}
}
}
break SEARCH ;
break SEARCH ;
@ -540,9 +540,7 @@ public class ObjectDirectory extends FileObjectDatabase {
pList = scanPacks ( pList ) ;
pList = scanPacks ( pList ) ;
continue SEARCH ;
continue SEARCH ;
} catch ( IOException e ) {
} catch ( IOException e ) {
// Assume the pack is corrupted.
handlePackError ( e , p ) ;
//
removePack ( p ) ;
}
}
}
}
break SEARCH ;
break SEARCH ;
@ -552,6 +550,28 @@ public class ObjectDirectory extends FileObjectDatabase {
h . db . selectObjectRepresentation ( packer , otp , curs ) ;
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
@Override
InsertLooseObjectResult insertUnpackedObject ( File tmp , ObjectId id ,
InsertLooseObjectResult insertUnpackedObject ( File tmp , ObjectId id ,
boolean createDuplicate ) throws IOException {
boolean createDuplicate ) throws IOException {