/** {@inheritDoc} */ @Override protected void onPackHeader(long objCnt) throws IOException { if (expectedObjectCount >= 0) { // Some DFS pack files don't contain the correct object count, e.g. // INSERT/RECEIVE packs don't always contain the correct object // count in their headers. Overwrite the expected object count // after parsing the pack header. setExpectedObjectCount(expectedObjectCount); } }
/** {@inheritDoc} */ @Override protected int readDatabase(byte[] dst, int pos, int cnt) throws IOException { // read from input instead of database. int n = read(offset, dst, pos, cnt); if (n > 0) { offset += n; } return n; }
private void verifyPack(ProgressMonitor pm, FsckError errors, DfsReader ctx, DfsPackFile pack, ReadableChannel ch) throws IOException, CorruptPackIndexException { FsckPackParser fpp = new FsckPackParser(objdb, ch); fpp.setObjectChecker(objChecker); fpp.overwriteObjectCount(pack.getPackDescription().getObjectCount()); fpp.parse(pm); errors.getCorruptObjects().addAll(fpp.getCorruptObjects()); fpp.verifyIndex(pack.getPackIndex(ctx)); }
private void checkPacks(ProgressMonitor pm, FsckError errors) throws IOException, FileNotFoundException { try (DfsReader ctx = objdb.newReader()) { for (DfsPackFile pack : objdb.getPacks()) { DfsPackDescription packDesc = pack.getPackDescription(); if (packDesc.getPackSource() == PackSource.UNREACHABLE_GARBAGE) { continue; } try (ReadableChannel rc = objdb.openFile(packDesc, PACK)) { verifyPack(pm, errors, ctx, pack, rc); } catch (MissingObjectException e) { errors.getMissingObjects().add(e.getObjectId()); } catch (CorruptPackIndexException e) { errors.getCorruptIndices().add(new CorruptIndex( pack.getPackDescription().getFileName(INDEX), e.getErrorType())); } } } checkGitModules(pm, errors); }
throws CorruptPackIndexException { ObjectIdOwnerMap<ObjFromPack> inPack = new ObjectIdOwnerMap<>(); for (int i = 0; i < getObjectCount(); i++) { PackedObjectInfo entry = getObject(i); inPack.add(new ObjFromPack(entry));
private void checkGitModules(ProgressMonitor pm, FsckError errors) throws IOException { pm.beginTask(JGitText.get().validatingGitModules, objChecker.getGitsubmodules().size()); for (GitmoduleEntry entry : objChecker.getGitsubmodules()) { AnyObjectId blobId = entry.getBlobId(); ObjectLoader blob = objdb.open(blobId, Constants.OBJ_BLOB); try { SubmoduleValidator.assertValidGitModulesFile( new String(blob.getBytes(), UTF_8)); } catch (SubmoduleValidationException e) { CorruptObject co = new FsckError.CorruptObject( blobId.toObjectId(), Constants.OBJ_BLOB, e.getFsckMessageId()); errors.getCorruptObjects().add(co); } pm.update(1); } pm.endTask(); }
&& tip.getType() != Constants.OBJ_COMMIT) { errors.getNonCommitHeads().add(r.getLeaf().getName()); errors.getMissingObjects().add(e.getObjectId()); continue; ow.checkConnectivity(); } catch (MissingObjectException e) { errors.getMissingObjects().add(e.getObjectId());
/** {@inheritDoc} */ @Override protected ObjectTypeAndSize seekDatabase(PackedObjectInfo obj, ObjectTypeAndSize info) throws IOException { crc.reset(); offset = obj.getOffset(); return readObjectHeader(info); }
int read(long channelPosition, byte[] dst, int pos, int cnt) throws IOException { long block = channelPosition / blockSize; byte[] bytes = readFromChannel(block); if (bytes == null) { return -1; } int offs = (int) (channelPosition - block * blockSize); int bytesToCopy = Math.min(cnt, bytes.length - offs); if (bytesToCopy < 1) { return -1; } System.arraycopy(bytes, offs, dst, pos, bytesToCopy); return bytesToCopy; }
/** {@inheritDoc} */ @Override protected void verifySafeObject(final AnyObjectId id, final int type, final byte[] data) { try { super.verifySafeObject(id, type, data); } catch (CorruptObjectException e) { corruptObjects.add( new CorruptObject(id.toObjectId(), type, e.getErrorType())); } }
/** * Constructor for FsckPackParser * * @param db * the object database which stores repository's data. * @param channel * readable channel of the pack file. */ public FsckPackParser(ObjectDatabase db, ReadableChannel channel) { super(db, Channels.newInputStream(channel)); this.channel = channel; setCheckObjectCollisions(false); this.crc = new CRC32(); this.blockSize = channel.blockSize() > 0 ? channel.blockSize() : 65536; }
/** * Verify the integrity and connectivity of all objects in the object * database. * * @param pm * callback to provide progress feedback during the check. * @return all errors about the repository. * @throws java.io.IOException * if encounters IO errors during the process. */ public FsckError check(ProgressMonitor pm) throws IOException { if (pm == null) { pm = NullProgressMonitor.INSTANCE; } FsckError errors = new FsckError(); if (!connectivityOnly) { objChecker.reset(); checkPacks(pm, errors); } checkConnectivity(pm, errors); return errors; }
private void verifyPack(ProgressMonitor pm, FsckError errors, DfsReader ctx, DfsPackFile pack, ReadableChannel ch) throws IOException, CorruptPackIndexException { FsckPackParser fpp = new FsckPackParser(objdb, ch); fpp.setObjectChecker(objChecker); fpp.overwriteObjectCount(pack.getPackDescription().getObjectCount()); fpp.parse(pm); errors.getCorruptObjects().addAll(fpp.getCorruptObjects()); fpp.verifyIndex(pack.getPackIndex(ctx)); }
/** {@inheritDoc} */ @Override protected ObjectTypeAndSize seekDatabase(UnresolvedDelta delta, ObjectTypeAndSize info) throws IOException { crc.reset(); offset = delta.getOffset(); return readObjectHeader(info); }
/** {@inheritDoc} */ @Override protected void onPackHeader(long objCnt) throws IOException { if (expectedObjectCount >= 0) { // Some DFS pack files don't contain the correct object count, e.g. // INSERT/RECEIVE packs don't always contain the correct object // count in their headers. Overwrite the expected object count // after parsing the pack header. setExpectedObjectCount(expectedObjectCount); } }
/** {@inheritDoc} */ @Override protected int readDatabase(byte[] dst, int pos, int cnt) throws IOException { // read from input instead of database. int n = read(offset, dst, pos, cnt); if (n > 0) { offset += n; } return n; }
int read(long channelPosition, byte[] dst, int pos, int cnt) throws IOException { long block = channelPosition / blockSize; byte[] bytes = readFromChannel(block); if (bytes == null) { return -1; } int offs = (int) (channelPosition - block * blockSize); int bytesToCopy = Math.min(cnt, bytes.length - offs); if (bytesToCopy < 1) { return -1; } System.arraycopy(bytes, offs, dst, pos, bytesToCopy); return bytesToCopy; }
/** {@inheritDoc} */ @Override protected void verifySafeObject(final AnyObjectId id, final int type, final byte[] data) { try { super.verifySafeObject(id, type, data); } catch (CorruptObjectException e) { corruptObjects.add( new CorruptObject(id.toObjectId(), type, e.getErrorType())); } }
/** {@inheritDoc} */ @Override protected ObjectTypeAndSize seekDatabase(PackedObjectInfo obj, ObjectTypeAndSize info) throws IOException { crc.reset(); offset = obj.getOffset(); return readObjectHeader(info); }
/** {@inheritDoc} */ @Override protected ObjectTypeAndSize seekDatabase(UnresolvedDelta delta, ObjectTypeAndSize info) throws IOException { crc.reset(); offset = delta.getOffset(); return readObjectHeader(info); }