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 { while (true) { file = owner.openAndSeekRepresentation(rep); FSRepresentationState repState = readRepresentationLine(file); repState.myFile = file; repState.myStart = file.position(); repState.myOffset = repState.myStart; repState.myEnd = repState.myStart + rep.getSize(); if (!repState.myIsDelta) { return repState; } buffer.clear(); int r = file.read(buffer); byte[] header = buffer.array(); if (!(header[0] == 'S' && header[1] == 'V' && header[2] == 'N' && r == 4)) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.FS_CORRUPT, "Malformed svndiff data in representation"); SVNErrorManager.error(err, SVNLogType.FSFS); } repState.myVersion = header[3]; repState.myChunkIndex = 0; repState.myOffset += 4; /* * Push this rep onto the list. If it's self-compressed, we're * done. */ result.addLast(repState); if (repState.myIsDeltaVsEmpty) { return null; } rep.setRevision(repState.myBaseRevision); rep.setOffset(repState.myBaseOffset); rep.setSize(repState.myBaseLength); rep.setTxnId(null); } } catch (IOException ioe) { file.close(); SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, ioe.getLocalizedMessage()); SVNErrorManager.error(err, ioe, SVNLogType.FSFS); } catch (SVNException svne) { file.close(); throw svne; } return null; }
public void close() throws IOException { if (myIsClosed) { return; } myIsClosed = true; final long truncateToSize[] = new long[] {-1}; try { ByteArrayInputStream target = new ByteArrayInputStream(myTextBuffer.toByteArray()); myDeltaGenerator.sendDelta(null, mySourceStream, mySourceOffset, target, this, false); final FSRepresentation rep = new FSRepresentation(); rep.setOffset(myRepOffset); long offset = myTargetFileOS.getPosition(); 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)); FSFS fsfs = myTxnRoot.getOwner(); final IFSRepresentationCacheManager reposCacheManager = fsfs.getRepositoryCacheManager(); if (reposCacheManager != null) { try { reposCacheManager.runReadTransaction( new IFSSqlJetTransaction() { public void run() throws SVNException { final FSRepresentation oldRep = reposCacheManager.getRepresentationByHash(rep.getSHA1HexDigest()); if (oldRep != null) { oldRep.setUniquifier(rep.getUniquifier()); oldRep.setMD5HexDigest(rep.getMD5HexDigest()); truncateToSize[0] = myRepOffset; myRevNode.setTextRepresentation(oldRep); } } }); } catch (SVNException e) { // explicitly ignore. SVNDebugLog.getDefaultLog().logError(SVNLogType.FSFS, e); } } if (truncateToSize[0] < 0) { myTargetFileOS.write("ENDREP\n".getBytes("UTF-8")); myRevNode.setTextRepresentation(rep); } myRevNode.setIsFreshTxnRoot(false); fsfs.putTxnRevisionNode(myRevNode.getId(), myRevNode); } catch (SVNException svne) { throw new IOException(svne.getMessage()); } finally { closeStreams(truncateToSize[0]); try { myTxnLock.unlock(); } catch (SVNException e) { // } FSWriteLock.release(myTxnLock); } }