final String md5Checksum = fields[4]; final FSRepresentation representation = new FSRepresentation(); representation.setRevision(revision); representation.setItemIndex(itemIndex); representation.setSize(size); representation.setExpandedSize(expandedSize); representation.setMD5HexDigest(md5Checksum); representation.setSHA1HexDigest(sha1Checksum); representation.setTxnId(txnId); representation.setUniquifier(fields[6]);
public void insert(final FSRepresentation representation, boolean rejectDup) throws SVNException { if (representation.getSHA1HexDigest() == null) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.BAD_CHECKSUM_KIND, "Only SHA1 checksums can be used as keys in the rep_cache table.\n"); SVNErrorManager.error(err, SVNLogType.FSFS); } FSRepresentation oldRep = getRepresentationByHash(representation.getSHA1HexDigest()); if (oldRep != null) { if (rejectDup && (oldRep.getRevision() != representation.getRevision() || oldRep.getOffset() != representation.getOffset() || oldRep.getSize() != representation.getSize() || oldRep.getExpandedSize() != representation.getExpandedSize())) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.FS_CORRUPT, "Representation key for checksum ''{0}'' exists in " + "filesystem ''{1}'' with a different value ({2},{3},{4},{5}) than what we were about to store ({6},{7},{8},{9})", new Object[] { representation.getSHA1HexDigest(), myFSFS.getRepositoryRoot(), String.valueOf(oldRep.getRevision()), String.valueOf(oldRep.getOffset()), String.valueOf(oldRep.getSize()), String.valueOf(oldRep.getExpandedSize()), String.valueOf(representation.getRevision()), String.valueOf(representation.getOffset()), String.valueOf(representation.getSize()), String.valueOf(representation.getExpandedSize()) }); SVNErrorManager.error(err, SVNLogType.FSFS); } return; } try { myTable.insert(new Object[] { representation.getSHA1HexDigest(), new Long(representation.getRevision()), new Long(representation.getOffset()), new Long(representation.getSize()), new Long(representation.getExpandedSize()) }); } catch (SqlJetException e) { SVNErrorManager.error(convertError(e), SVNLogType.FSFS); } }
public static boolean compareRepresentations(FSRepresentation r1, FSRepresentation r2) { if (r1 == r2) { return true; } else if (r1 == null) { return false; } return r1.equals(r2); }
public FSRepresentation(FSRepresentation representation) { myRevision = representation.getRevision(); myOffset = representation.getOffset(); mySize = representation.getSize(); myExpandedSize = representation.getExpandedSize(); myHexDigest = representation.getHexDigest(); myTxnId = representation.myTxnId; }
public boolean equals(Object obj) { if (obj == null || obj.getClass() != FSRepresentation.class) { return false; } FSRepresentation rep = (FSRepresentation) obj; return myRevision == rep.getRevision() && myOffset == rep.getOffset(); }
public FSFile openAndSeekRepresentation(FSRepresentation rep) throws SVNException { if (!rep.isTxn()) { return openAndSeekRevision(rep.getRevision(), rep.getOffset()); } return openAndSeekTransaction(rep); }
if (revNode.getTextRepresentation() != null && revNode.getTextRepresentation().isTxn()) { SVNProperties unparsedEntries = unparseDirEntries(namesToEntries); FSRepresentation textRep = revNode.getTextRepresentation(); textRep.setTxnId(null); textRep.setRevision(revision); try { textRep.setOffset(protoFile.getPosition()); final MessageDigest checksum = MessageDigest.getInstance("MD5"); long size = writeHashRepresentation(unparsedEntries, protoFile, checksum); String hexDigest = SVNFileUtil.toHexDigest(checksum); textRep.setSize(size); textRep.setMD5HexDigest(hexDigest); textRep.setExpandedSize(textRep.getSize()); } catch (NoSuchAlgorithmException nsae) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, if (revNode.getTextRepresentation() != null && revNode.getTextRepresentation().isTxn()) { FSRepresentation textRep = revNode.getTextRepresentation(); textRep.setTxnId(null); textRep.setRevision(revision); if (revNode.getPropsRepresentation() != null && revNode.getPropsRepresentation().isTxn()) { SVNProperties props = revNode.getProperties(owner); FSRepresentation propsRep = revNode.getPropsRepresentation(); try { propsRep.setOffset(protoFile.getPosition()); final MessageDigest checksum = MessageDigest.getInstance("MD5"); long size = writeHashRepresentation(props, protoFile, checksum); String hexDigest = SVNFileUtil.toHexDigest(checksum);
myDeltaGenerator.sendDelta(null, mySourceStream, mySourceOffset, target, this, false); FSRepresentation rep = new FSRepresentation(); rep.setOffset(myRepOffset); rep.setSize(offset - myDeltaStart); rep.setExpandedSize(myRepSize); rep.setTxnId(myRevNode.getId().getTxnID()); String uniqueSuffix = myTxnRoot.getNewTxnNodeId(); String uniquifier = rep.getTxnId() + '/' + uniqueSuffix; rep.setUniquifier(uniquifier); rep.setRevision(SVNRepository.INVALID_REVISION); rep.setMD5HexDigest(SVNFileUtil.toHexDigest(myMD5Digest)); rep.setSHA1HexDigest(SVNFileUtil.toHexDigest(mySHA1Digest)); IFSRepresentationCacheManager reposCacheManager = fsfs.getRepositoryCacheManager(); if (reposCacheManager != null) { oldRepresentation = reposCacheManager.getRepresentationByHash(rep.getSHA1HexDigest()); oldRepresentation.setUniquifier(rep.getUniquifier()); oldRepresentation.setMD5HexDigest(rep.getMD5HexDigest()); truncateToSize = myRepOffset; myRevNode.setTextRepresentation(oldRepresentation);
private FSRepresentationState buildRepresentationList(FSRepresentation firstRep, LinkedList result, FSFS owner) throws SVNException { FSFile file = null; FSRepresentation rep = new FSRepresentation(firstRep); ByteBuffer buffer = ByteBuffer.allocate(4); try { repState.myStart = file.position(); repState.myOffset = repState.myStart; repState.myEnd = repState.myStart + rep.getSize(); if (!repState.myIsDelta) { return repState; return null; rep.setRevision(repState.myBaseRevision); rep.setOffset(repState.myBaseOffset); rep.setSize(repState.myBaseLength); rep.setTxnId(null);
public void close() throws IOException { if (myIsClosed) { return; } myIsClosed = true; try { ByteArrayInputStream target = new ByteArrayInputStream(myTextBuffer.array(), 0, myTextBuffer.position()); myDeltaGenerator.sendDelta(null, mySourceStream, mySourceOffset, target, this, false); FSRepresentation rep = new FSRepresentation(); rep.setOffset(myRepOffset); long offset = myTargetFile.getPosition(); rep.setSize(offset - myDeltaStart); rep.setExpandedSize(myRepSize); rep.setTxnId(myRevNode.getId().getTxnID()); rep.setRevision(FSRepository.SVN_INVALID_REVNUM); rep.setHexDigest(SVNFileUtil.toHexDigest(myDigest)); myTargetFile.write("ENDREP\n".getBytes("UTF-8")); myRevNode.setTextRepresentation(rep); myTxnRoot.getOwner().putTxnRevisionNode(myRevNode.getId(), myRevNode); } catch (SVNException svne) { throw new IOException(svne.getMessage()); } finally { closeStreams(); } }
if (textRep == null || !textRep.isTxn()) { Map entries = parentRevNode.getDirEntries(getOwner()); SVNProperties unparsedEntries = unparseDirEntries(entries); dst = SVNFileUtil.openFileForWriting(childrenFile); SVNWCProperties.setProperties(unparsedEntries, dst, SVNWCProperties.SVN_HASH_TERMINATOR); textRep = new FSRepresentation(); textRep.setRevision(SVNRepository.INVALID_REVISION); textRep.setTxnId(myTxnID); String uniqueSuffix = getNewTxnNodeId(); String uniquifier = myTxnID + '/' + uniqueSuffix; textRep.setUniquifier(uniquifier); parentRevNode.setTextRepresentation(textRep); parentRevNode.setIsFreshTxnRoot(false);
public FSRepresentation getRepresentationByHash(String hash) throws SVNException { FSRepresentationCacheRecord cache = getByHash(hash); if (cache != null) { FSRepresentation representation = new FSRepresentation(); representation.setExpandedSize(cache.getExpandedSize()); representation.setOffset(cache.getOffset()); representation.setRevision(cache.getRevision()); representation.setSize(cache.getSize()); representation.setSHA1HexDigest(cache.getHash()); return representation; } return null; }
oldRepresentation = representationsMap.get(representation.getSHA1HexDigest()); if (oldRepresentation == null && representation.isTxn()) { File file = pathTxnSha1(fsfs, representation, representation.getTxnId()); SVNFileType fileType = SVNFileType.getType(file); if (fileType == SVNFileType.FILE) { String representationString = SVNFileUtil.readFile(file); oldRepresentation = FSRepresentation.parse(representationString); return null; if (oldRepresentation.getExpandedSize() != representation.getExpandedSize() || (representation.getExpandedSize() == 0 && oldRepresentation.getSize() != representation.getSize())) { oldRepresentation = null; } else { oldRepresentation.setMD5HexDigest(representation.getMD5HexDigest()); oldRepresentation.setUniquifier(representation.getUniquifier());
private FSRepresentationState buildRepresentationList(FSRepresentation firstRep, LinkedList result, FSFS owner) throws SVNException { FSFile file = null; FSRepresentation rep = new FSRepresentation(firstRep); ByteBuffer buffer = ByteBuffer.allocate(4); try { repState.myStart = file.position(); repState.myOffset = repState.myStart; repState.myEnd = repState.myStart + rep.getSize(); if (!repState.myIsDelta) { return repState; return null; rep.setRevision(repState.myBaseRevision); rep.setItemIndex(repState.myBaseOffset); rep.setSize(repState.myBaseLength); rep.setTxnId(null);
if (revNode.getTextRepresentation() != null && revNode.getTextRepresentation().isTxn()) { Map unparsedEntries = unparseDirEntries(namesToEntries); FSRepresentation textRep = revNode.getTextRepresentation(); textRep.setTxnId(null); textRep.setRevision(revision); try { textRep.setOffset(protoFile.getPosition()); final MessageDigest checksum = MessageDigest.getInstance("MD5"); long size = writeHashRepresentation(unparsedEntries, protoFile, checksum); String hexDigest = SVNFileUtil.toHexDigest(checksum); textRep.setSize(size); textRep.setHexDigest(hexDigest); textRep.setExpandedSize(textRep.getSize()); } catch (NoSuchAlgorithmException nsae) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, "MD5 implementation not found: {0}", nsae.getLocalizedMessage()); if (revNode.getTextRepresentation() != null && revNode.getTextRepresentation().isTxn()) { FSRepresentation textRep = revNode.getTextRepresentation(); textRep.setTxnId(null); textRep.setRevision(revision); if (revNode.getPropsRepresentation() != null && revNode.getPropsRepresentation().isTxn()) { Map props = revNode.getProperties(owner); FSRepresentation propsRep = revNode.getPropsRepresentation(); try { propsRep.setOffset(protoFile.getPosition()); final MessageDigest checksum = MessageDigest.getInstance("MD5"); long size = writeHashRepresentation(props, protoFile, checksum); String hexDigest = SVNFileUtil.toHexDigest(checksum);
public FSRepresentation getRepresentationByHash(String hash) throws SVNException { FSRepresentationCacheRecord cache = getByHash(hash); if (cache != null) { FSRepresentation representation = new FSRepresentation(); representation.setExpandedSize(cache.getExpandedSize()); representation.setItemIndex(cache.getOffset()); representation.setRevision(cache.getRevision()); representation.setSize(cache.getSize()); representation.setSHA1HexDigest(cache.getHash()); return representation; } return null; }
public void setProplist(FSRevisionNode node, Map properties) throws SVNException { if (!node.getId().isTxn()) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.FS_NOT_MUTABLE, "Can't set proplist on *immutable* node-revision {0}", node.getId()); SVNErrorManager.error(err); } File propsFile = getTransactionRevNodePropsFile(node.getId()); SVNProperties.setProperties(properties, propsFile, SVNFileUtil.createUniqueFile(propsFile.getParentFile(), propsFile.getName(), ".tmp"), SVNProperties.SVN_HASH_TERMINATOR); if (node.getPropsRepresentation() == null || !node.getPropsRepresentation().isTxn()) { FSRepresentation mutableRep = new FSRepresentation(); mutableRep.setTxnId(node.getId().getTxnID()); node.setPropsRepresentation(mutableRep); getOwner().putTxnRevisionNode(node.getId(), node); } }
header = FSRepresentation.REP_DELTA + " " + baseRep.getRevision() + " " + baseRep.getOffset() + " " + baseRep.getSize() + "\n"; } else { header = FSRepresentation.REP_DELTA + "\n";
public void insert(final FSRepresentation representation, boolean rejectDup) throws SVNException { if (representation.getSHA1HexDigest() == null) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.BAD_CHECKSUM_KIND, "Only SHA1 checksums can be used as keys in the rep_cache table.\n"); SVNErrorManager.error(err, SVNLogType.FSFS); } FSRepresentation oldRep = getRepresentationByHash(representation.getSHA1HexDigest()); if (oldRep != null) { if (rejectDup && (oldRep.getRevision() != representation.getRevision() || oldRep.getItemIndex() != representation.getItemIndex() || oldRep.getSize() != representation.getSize() || oldRep.getExpandedSize() != representation.getExpandedSize())) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.FS_CORRUPT, "Representation key for checksum ''{0}'' exists in " + "filesystem ''{1}'' with a different value ({2},{3},{4},{5}) than what we were about to store ({6},{7},{8},{9})", new Object[] { representation.getSHA1HexDigest(), myFSFS.getRepositoryRoot(), String.valueOf(oldRep.getRevision()), String.valueOf(oldRep.getItemIndex()), String.valueOf(oldRep.getSize()), String.valueOf(oldRep.getExpandedSize()), String.valueOf(representation.getRevision()), String.valueOf(representation.getItemIndex()), String.valueOf(representation.getSize()), String.valueOf(representation.getExpandedSize()) }); SVNErrorManager.error(err, SVNLogType.FSFS); } return; } try { myTable.insert(new Object[] { representation.getSHA1HexDigest(), new Long(representation.getRevision()), new Long(representation.getItemIndex()), new Long(representation.getSize()), new Long(representation.getExpandedSize()) }); } catch (SqlJetException e) { SVNErrorManager.error(convertError(e), SVNLogType.FSFS); } }