protected void relocate(List targets) throws SVNException { if (targets.size() < 2) { SVNErrorManager.error( SVNErrorMessage.create(SVNErrorCode.CL_INSUFFICIENT_ARGS), SVNLogType.CLIENT); } SVNPath from = new SVNPath((String) targets.get(0)); SVNPath to = new SVNPath((String) targets.get(1)); if (from.isURL() != to.isURL() || !from.isURL()) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.INCORRECT_PARAMS, "''{0}'' to ''{1}'' is not a valid relocation", new Object[] {from.getTarget(), to.getTarget()}); SVNErrorManager.error(err, SVNLogType.CLIENT); } SVNUpdateClient client = getSVNEnvironment().getClientManager().getUpdateClient(); if (targets.size() == 2) { SVNPath target = new SVNPath(""); client.doRelocate( target.getFile(), from.getURL(), to.getURL(), getSVNEnvironment().getDepth().isRecursive()); } else { for (int i = 2; i < targets.size(); i++) { SVNPath target = new SVNPath((String) targets.get(i)); client.doRelocate( target.getFile(), from.getURL(), to.getURL(), getSVNEnvironment().getDepth().isRecursive()); } } }
private static void verifyLock(SVNLock lock, Collection lockTokens, String username) throws SVNException { if (username == null || "".equals(username)) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.FS_NO_USER, "Cannot verify lock on path ''{0}''; no username available", lock.getPath()); SVNErrorManager.error(err, SVNLogType.FSFS); } else if (username.compareTo(lock.getOwner()) != 0) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.FS_LOCK_OWNER_MISMATCH, "User {0} does not own lock on path ''{1}'' (currently locked by {2})", new Object[] {username, lock.getPath(), lock.getOwner()}); SVNErrorManager.error(err, SVNLogType.FSFS); } if (lockTokens.contains(lock.getID())) { return; } SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.FS_BAD_LOCK_TOKEN, "Cannot verify lock on path ''{0}''; no matching lock-token available", lock.getPath()); SVNErrorManager.error(err, SVNLogType.FSFS); }
public static SVNAdminArea open(File path, Level logLevel) throws SVNException { SVNErrorMessage error = null; int wcFormatVersion = -1; Collection enabledFactories = getSelector().getEnabledFactories(path, ourFactories, false); File adminDir = new Resource(path, SVNFileUtil.getAdminDirectoryName()); File entriesFile = new Resource(adminDir, "entries"); if (adminDir.isDirectory() && entriesFile.isFile()) { for (Iterator factories = enabledFactories.iterator(); factories.hasNext(); ) { SVNAdminAreaFactory factory = (SVNAdminAreaFactory) factories.next(); try { wcFormatVersion = factory.getVersion(path); if (wcFormatVersion > factory.getSupportedVersion()) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.WC_UNSUPPORTED_FORMAT, "The path ''{0}'' appears to be part of a Subversion 1.7 or greater\n" + "working copy. Please upgrade your Subversion client to use this\n" + "working copy.", path); SVNErrorManager.error(err, SVNLogType.WC); } else if (wcFormatVersion < factory.getSupportedVersion()) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.WC_UNSUPPORTED_FORMAT, "Working copy format of {0} is too old ({1}); please check out your working copy again", new Object[] {path, new Integer(wcFormatVersion)}); SVNErrorManager.error(err, SVNLogType.WC); } } catch (SVNException e) { if (error != null) { error.setChildErrorMessage(e.getErrorMessage()); } else { error = e.getErrorMessage(); } continue; } SVNAdminArea adminArea = factory.doOpen(path, wcFormatVersion); if (adminArea != null) { adminArea.setWorkingCopyFormatVersion(wcFormatVersion); return adminArea; } } } if (error == null) { if (path != null) { checkWCNG(path.getAbsoluteFile(), path); } error = SVNErrorMessage.create( SVNErrorCode.WC_NOT_DIRECTORY, "''{0}'' is not a working copy", path); } if (error.getErrorCode() == SVNErrorCode.WC_UNSUPPORTED_FORMAT) { error.setChildErrorMessage(null); } SVNErrorManager.error(error, logLevel, SVNLogType.WC); return null; }
private SVNErrorMessage readData( InputStream is, String method, String path, DefaultHandler handler) throws FactoryConfigurationError, UnsupportedEncodingException, IOException { try { if (mySAXParser == null) { mySAXParser = getSAXParserFactory().newSAXParser(); } XMLReader reader = new XMLReader(is); while (!reader.isClosed()) { org.xml.sax.XMLReader xmlReader = mySAXParser.getXMLReader(); xmlReader.setContentHandler(handler); xmlReader.setDTDHandler(handler); xmlReader.setErrorHandler(handler); xmlReader.setEntityResolver(NO_ENTITY_RESOLVER); xmlReader.parse(new InputSource(reader)); } } catch (SAXException e) { if (e instanceof SAXParseException) { if (handler instanceof DAVErrorHandler) { // failed to read svn-specific error, return null. return null; } } else if (e.getException() instanceof SVNException) { return ((SVNException) e.getException()).getErrorMessage(); } else if (e.getCause() instanceof SVNException) { return ((SVNException) e.getCause()).getErrorMessage(); } return SVNErrorMessage.create( SVNErrorCode.RA_DAV_REQUEST_FAILED, "Processing {0} request response failed: {1} ({2}) ", new Object[] {method, e.getMessage(), path}); } catch (ParserConfigurationException e) { return SVNErrorMessage.create( SVNErrorCode.RA_DAV_REQUEST_FAILED, "XML parser configuration error while processing {0} request response: {1} ({2}) ", new Object[] {method, e.getMessage(), path}); } catch (EOFException e) { // skip it. } finally { if (mySAXParser != null) { // to avoid memory leaks when connection is cached. org.xml.sax.XMLReader xmlReader = null; try { xmlReader = mySAXParser.getXMLReader(); } catch (SAXException e) { } if (xmlReader != null) { xmlReader.setContentHandler(DEFAULT_SAX_HANDLER); xmlReader.setDTDHandler(DEFAULT_SAX_HANDLER); xmlReader.setErrorHandler(DEFAULT_SAX_HANDLER); xmlReader.setEntityResolver(NO_ENTITY_RESOLVER); } } myRepository.getDebugLog().flushStream(is); } return null; }
public static int checkWC(File path, boolean useSelector, Level logLevel) throws SVNException { Collection enabledFactories = ourFactories; if (useSelector) { enabledFactories = getSelector().getEnabledFactories(path, enabledFactories, false); } SVNErrorMessage error = null; int version = -1; for (Iterator factories = enabledFactories.iterator(); factories.hasNext(); ) { SVNAdminAreaFactory factory = (SVNAdminAreaFactory) factories.next(); try { version = factory.doCheckWC(path, logLevel); if (version == 0) { return version; } if (version > factory.getSupportedVersion()) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.WC_UNSUPPORTED_FORMAT, "The path ''{0}'' appears to be part of a Subversion 1.7 or greater\n" + "working copy. Please upgrade your Subversion client to use this\n" + "working copy.", path); SVNErrorManager.error(err, SVNLogType.WC); } else if (version < factory.getSupportedVersion()) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.WC_UNSUPPORTED_FORMAT, "Working copy format of {0} is too old ({1}); please check out your working copy again", new Object[] {path, new Integer(version)}); SVNErrorManager.error(err, SVNLogType.WC); } } catch (SVNException e) { if (error != null) { error.setChildErrorMessage(e.getErrorMessage()); } else { error = e.getErrorMessage(); } continue; } return version; } if (error == null) { if (path != null) { checkWCNG(path.getAbsoluteFile(), path); } error = SVNErrorMessage.create( SVNErrorCode.WC_NOT_DIRECTORY, "''{0}'' is not a working copy", path); } if (error.getErrorCode() == SVNErrorCode.WC_UNSUPPORTED_FORMAT) { error.setChildErrorMessage(null); } SVNErrorManager.error(error, logLevel, SVNLogType.WC); return 0; }
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; }
private static boolean checkAdminAreaExists(File dir, String url, long revision) throws SVNException { File adminDir = new Resource(dir, SVNFileUtil.getAdminDirectoryName()); if (adminDir.exists() && !adminDir.isDirectory()) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.WC_OBSTRUCTED_UPDATE, "''{0}'' is not a directory", dir); SVNErrorManager.error(err, SVNLogType.WC); } else if (!adminDir.exists()) { return false; } boolean wcExists = false; try { readFormatVersion(adminDir); wcExists = true; } catch (SVNException svne) { return false; } if (wcExists) { SVNWCAccess wcAccess = SVNWCAccess.newInstance(null); SVNAdminArea adminArea = null; SVNEntry entry = null; try { adminArea = wcAccess.open(dir, false, 0); entry = adminArea.getVersionedEntry(adminArea.getThisDirName(), false); } finally { wcAccess.closeAdminArea(dir); } if (!entry.isScheduledForDeletion()) { if (entry.getRevision() != revision) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.WC_OBSTRUCTED_UPDATE, "Revision {0} doesn''t match existing revision {1} in ''{2}''", new Object[] {new Long(revision), new Long(entry.getRevision()), dir}); SVNErrorManager.error(err, SVNLogType.WC); } if (!url.equals(entry.getURL())) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.WC_OBSTRUCTED_UPDATE, "URL ''{0}'' doesn''t match existing URL ''{1}'' in ''{2}''", new Object[] {url, entry.getURL(), dir}); SVNErrorManager.error(err, SVNLogType.WC); } } } return wcExists; }
private FSOutputStream( FSRevisionNode revNode, CountingOutputStream targetFileOS, File targetFile, InputStream source, long deltaStart, long repSize, long repOffset, FSTransactionRoot txnRoot, boolean compress, FSWriteLock txnLock) throws SVNException { myTxnRoot = txnRoot; myTargetFileOS = targetFileOS; myTargetFile = targetFile; mySourceStream = source; myDeltaStart = deltaStart; myRepSize = repSize; myRepOffset = repOffset; isHeaderWritten = false; myRevNode = revNode; mySourceOffset = 0; myIsClosed = false; myTxnLock = txnLock; myDeltaGenerator = new SVNDeltaGenerator(SVN_DELTA_WINDOW_SIZE); myTextBuffer = new ByteArrayOutputStream(); try { myMD5Digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException nsae) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.IO_ERROR, "MD5 implementation not found: {0}", nsae.getLocalizedMessage()); SVNErrorManager.error(err, nsae, SVNLogType.FSFS); } try { mySHA1Digest = MessageDigest.getInstance("SHA1"); } catch (NoSuchAlgorithmException nsae) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.IO_ERROR, "SHA1 implementation not found: {0}", nsae.getLocalizedMessage()); SVNErrorManager.error(err, nsae, SVNLogType.FSFS); } myIsCompress = compress; }
public static DAVLockInfoProvider createLockInfoProvider( ServletDAVHandler owner, boolean readOnly) throws SVNException { String clientOptions = owner.getRequestHeader(ServletDAVHandler.SVN_OPTIONS_HEADER); DAVLockInfoProvider provider = new DAVLockInfoProvider(); provider.myOwner = owner; provider.myIsReadOnly = readOnly; if (clientOptions != null) { if (clientOptions.indexOf(LOCK_BREAK_OPTION) != -1) { provider.myIsBreakLock = true; } if (clientOptions.indexOf(LOCK_STEAL_OPTION) != -1) { provider.myIsStealLock = true; } if (clientOptions.indexOf(KEEP_LOCKS_OPTION) != -1) { provider.myIsKeepLocks = true; } } String versionName = owner.getRequestHeader(ServletDAVHandler.SVN_VERSION_NAME_HEADER); provider.myWorkingRevision = SVNRepository.INVALID_REVISION; if (versionName != null) { try { provider.myWorkingRevision = Long.parseLong(versionName); } catch (NumberFormatException nfe) { SVNErrorManager.error( SVNErrorMessage.create(SVNErrorCode.RA_DAV_REQUEST_FAILED, nfe), SVNLogType.NETWORK); } } return provider; }
public SVNProperties asMap() throws SVNException { SVNProperties result = new SVNProperties(); if (isEmpty()) { return result; } ByteArrayOutputStream nameOS = new ByteArrayOutputStream(); InputStream is = SVNFileUtil.openFileForReading(getFile(), SVNLogType.WC); try { while (readProperty('K', is, nameOS)) { String name = new String(nameOS.toByteArray(), "UTF-8"); nameOS.reset(); readProperty('V', is, nameOS); byte[] value = nameOS.toByteArray(); result.put(name, value); nameOS.reset(); } } catch (IOException e) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.IO_ERROR, "Cannot read properties file ''{0}'': {1}", new Object[] {getFile(), e.getLocalizedMessage()}); SVNErrorManager.error(err, e, SVNLogType.WC); } finally { SVNFileUtil.closeFile(is); } return result; }
public static boolean areFileContentsChanged( FSRoot root1, String path1, FSRoot root2, String path2) throws SVNException { if (root1.checkNodeKind(path1) != SVNNodeKind.FILE) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.FS_GENERAL, "''{0}'' is not a file", path1); SVNErrorManager.error(err); } if (root2.checkNodeKind(path2) != SVNNodeKind.FILE) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.FS_GENERAL, "''{0}'' is not a file", path2); SVNErrorManager.error(err); } FSRevisionNode revNode1 = root1.getRevisionNode(path1); FSRevisionNode revNode2 = root2.getRevisionNode(path2); return !areRepresentationsEqual(revNode1, revNode2, false); }
private static int readFormatVersion(File adminDir) throws SVNException { SVNErrorMessage error = null; int version = -1; Collection enabledFactories = getSelector().getEnabledFactories(adminDir.getParentFile(), ourFactories, false); for (Iterator factories = enabledFactories.iterator(); factories.hasNext(); ) { SVNAdminAreaFactory factory = (SVNAdminAreaFactory) factories.next(); try { version = factory.getVersion(adminDir); } catch (SVNException e) { error = e.getErrorMessage(); continue; } return version; } if (error == null) { error = SVNErrorMessage.create( SVNErrorCode.WC_NOT_DIRECTORY, "''{0}'' is not a working copy", adminDir); } SVNErrorManager.error(error, SVNLogType.WC); return -1; }
public void update( SVNURL url, long revision, String target, boolean recursive, ISVNReporterBaton reporter, ISVNEditor editor) throws SVNException { target = target == null ? "" : target; if (url == null) { SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.BAD_URL, "URL can not be NULL")); } Object[] buffer = new Object[] { "switch", getRevisionObject(revision), target, Boolean.valueOf(recursive), url.toString() }; try { openConnection(); write("(w((n)sws))", buffer); authenticate(); reporter.report(this); authenticate(); read("*E", new Object[] {editor}, true); write("(w())", new Object[] {"success"}); read("[()]", null, true); } catch (SVNException e) { closeSession(); throw e; } finally { closeConnection(); } }
private Object[] read(String template, Object[] values, boolean readMalformedData) throws SVNException { if (myConnection == null) { SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.RA_SVN_CONNECTION_CLOSED)); } return myConnection.read(template, values, readMalformedData); }
public void bumpTo(SVNSqlJetDb sDb, File wcRootAbsPath) throws SVNException { // -- STMT_HAS_WORKING_NODES // SELECT 1 FROM nodes WHERE op_depth > 0 // LIMIT 1 SVNSqlJetSelectFieldsStatement<SVNWCDbSchema.NODES__Fields> stmt = new SVNSqlJetSelectFieldsStatement<SVNWCDbSchema.NODES__Fields>( sDb, SVNWCDbSchema.NODES) { protected void defineFields() { fields.add(SVNWCDbSchema.NODES__Fields.wc_id); } protected boolean isFilterPassed() throws SVNException { return getColumnLong(SVNWCDbSchema.NODES__Fields.op_depth) > 0; } }; boolean haveRow = false; try { haveRow = stmt.next(); } finally { stmt.reset(); } if (haveRow) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.UNSUPPORTED_FEATURE, "The working copy at ''{0}'' is format 22 with WORKING nodes; use a format 22 client to diff/revert before using this client", wcRootAbsPath); SVNErrorManager.error(err, SVNLogType.WC); } setVersion(sDb, (int) 23); }
/** * Handles a next log entry producing corresponding xml. * * @param logEntry log entry * @throws SVNException */ public void handleLogEntry(SVNLogEntry logEntry) throws SVNException { if (logEntry.getChangedPaths() != null && relativePath != null) { // convert external path reference to local relative path Map<String, SVNLogEntryPath> changedPaths = new HashMap<String, SVNLogEntryPath>(); for (SVNLogEntryPath entry : logEntry.getChangedPaths().values()) { String localPath = entry.getPath().substring(1); // path in svn log start with a '/' if (localPath.startsWith(relativeUrl)) { localPath = relativePath + localPath.substring(relativeUrl.length()); } // can't use entry.setPath(localPath) as FSPathChange duplicate myPath attribute then // setPath().getPath() don't return same value changedPaths.put( localPath, new SVNLogEntryPath( localPath, entry.getType(), entry.getCopyPath(), entry.getCopyRevision())); } logEntry.getChangedPaths().clear(); logEntry.getChangedPaths().putAll(changedPaths); } try { if (filter == null || !filter.hasExclusionRule() || filter.isIncluded(logEntry)) { sendToHandler(logEntry); } } catch (SAXException e) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.XML_MALFORMED, e.getLocalizedMessage()); SVNErrorManager.error(err, e, SVNLogType.DEFAULT); } }
private FSInputStream(SVNDeltaCombiner combiner, FSRepresentation representation, FSFS owner) throws SVNException { myCombiner = combiner; myChunkIndex = 0; isChecksumFinalized = false; myHexChecksum = representation.getMD5HexDigest(); myOffset = 0; myLength = representation.getExpandedSize(); try { myDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException nsae) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.IO_ERROR, "MD5 implementation not found: {0}", nsae.getLocalizedMessage()); SVNErrorManager.error(err, nsae, SVNLogType.FSFS); } try { buildRepresentationList(representation, myRepStateList, owner); } catch (SVNException svne) { /* * Something terrible has happened while building rep list, need to * close any files still opened */ close(); throw svne; } }
public void deleteNode(String path) throws SVNException { FSTransactionRoot txnRoot = getTxnRoot(); FSParentPath parentPath = txnRoot.openPath(path, true, true); SVNNodeKind kind = parentPath.getRevNode().getType(); if (parentPath.getParent() == null) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.FS_ROOT_DIR, "The root directory cannot be deleted"); SVNErrorManager.error(err, SVNLogType.FSFS); } if ((txnRoot.getTxnFlags() & FSTransactionRoot.SVN_FS_TXN_CHECK_LOCKS) != 0) { allowLockedOperation(myFSFS, path, myAuthor, myLockTokens, true, false); } makePathMutable(parentPath.getParent(), path); txnRoot.deleteEntry(parentPath.getParent().getRevNode(), parentPath.getEntryName()); txnRoot.removeRevNodeFromCache(parentPath.getAbsPath()); if (myFSFS.supportsMergeInfo()) { long mergeInfoCount = parentPath.getRevNode().getMergeInfoCount(); if (mergeInfoCount > 0) { incrementMergeInfoUpTree(parentPath.getParent(), -mergeInfoCount); } } addChange( path, parentPath.getRevNode().getId(), FSPathChangeKind.FS_PATH_CHANGE_DELETE, false, false, SVNRepository.INVALID_REVISION, null, kind); }
private boolean for17move( final SvnVcs vcs, final File src, final File dst, boolean undo, SVNStatus srcStatus) throws SVNException { if (srcStatus != null && srcStatus.getCopyFromURL() == null) { undo = false; } if (undo) { myUndoingMove = true; createRevertAction(vcs, dst, true).execute(); copyUnversionedMembersOfDirectory(src, dst); if (srcStatus == null || SvnVcs.svnStatusIsUnversioned(srcStatus)) { FileUtil.delete(src); } else { createRevertAction(vcs, src, true).execute(); } restoreFromUndoStorage(dst); } else { if (doUsualMove(vcs, src)) return true; // check destination directory final SVNStatus dstParentStatus = getFileStatus(vcs, dst.getParentFile()); if (dstParentStatus == null || SvnVcs.svnStatusIsUnversioned(dstParentStatus)) { try { copyFileOrDir(src, dst); } catch (IOException e) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e); } createDeleteAction(vcs, src, true).execute(); return false; } moveFileWithSvn(vcs, src, dst); } return false; }
public SVNConflictResult handleConflict(SVNConflictDescription conflictDescription) throws SVNException { SVNConflictResult conflictResult = handleConflictNoStats(conflictDescription); if (conflictResult != null && conflictResult.getConflictChoice() != SVNConflictChoice.POSTPONE) { SVNConflictStats conflictStats = getConflictStats(); if (conflictDescription instanceof SVNTextConflictDescription) { conflictStats.incrementTextConflictsResolved( SVNFileUtil.getFilePath(conflictDescription.getPath())); } else if (conflictDescription instanceof SVNPropertyConflictDescription) { conflictStats.incrementPropConflictsResolved( SVNFileUtil.getFilePath(conflictDescription.getPath())); } else if (conflictDescription instanceof SVNTreeConflictDescription) { conflictStats.incrementTreeConflictsResolved( SVNFileUtil.getFilePath(conflictDescription.getPath())); } else { SVNErrorMessage errorMessage = SVNErrorMessage.create( SVNErrorCode.ASSERTION_FAIL, "Invalid conflict kind on ''{0}''", conflictDescription.getPath()); SVNErrorManager.error(errorMessage, SVNLogType.WC); } } return conflictResult; }
public void addChange( String path, FSID id, FSPathChangeKind changeKind, boolean textModified, boolean propsModified, long copyFromRevision, String copyFromPath, SVNNodeKind kind) throws SVNException { path = SVNPathUtil.canonicalizeAbsolutePath(path); OutputStream changesFile = null; try { FSTransactionRoot txnRoot = getTxnRoot(); changesFile = SVNFileUtil.openFileForWriting(txnRoot.getTransactionChangesFile(), true); FSPathChange pathChange = new FSPathChange( path, id, changeKind, textModified, propsModified, copyFromPath, copyFromRevision, kind); txnRoot.writeChangeEntry(changesFile, pathChange, true); } catch (IOException ioe) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, ioe.getLocalizedMessage()); SVNErrorManager.error(err, ioe, SVNLogType.FSFS); } finally { SVNFileUtil.closeFile(changesFile); } }
private void assertValidReplaceKind(File repositoryRoot, long revision, SVNNodeKind kind) throws SVNException { final CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder(); decoder.onMalformedInput(CodingErrorAction.IGNORE); decoder.onUnmappableCharacter(CodingErrorAction.IGNORE); final File revisionNodeFile = new File(repositoryRoot, "db/revs/0/" + revision); final InputStream in = SVNFileUtil.openFileForReading(revisionNodeFile); final StringBuffer buffer = new StringBuffer(); final String replaceString = "replace-" + kind; boolean replaceLineFound = false; try { while (true) { final String line = SVNFileUtil.readLineFromStream(in, buffer, decoder); if (line == null) { break; } buffer.setLength(0); if (line.indexOf(replaceString) >= 0) { replaceLineFound = true; break; } } } catch (IOException e) { SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.UNKNOWN, e), e, SVNLogType.CLIENT); } finally { SVNFileUtil.closeFile(in); } Assert.assertTrue( "Could not find 'replace-" + kind + "' string in revision node file", replaceLineFound); }
private void handleUnsupportedCommand(SVNException e, String message) throws SVNException { if (e.getErrorMessage() != null && e.getErrorMessage().getErrorCode() == SVNErrorCode.RA_SVN_UNKNOWN_CMD) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_NOT_IMPLEMENTED, message); SVNErrorManager.error(err, e.getErrorMessage()); } throw e; }
/** * Called when a new file has to be created. * * <p>For each 'addFile' call server will call 'closeFile' method after sending file properties * and contents. * * <p>This implementation creates empty file below root directory, file contents will be updated * later, and for empty files may not be sent at all. */ public void addFile(String path, String copyFromPath, long copyFromRevision) throws SVNException { File file = new File(myRootDirectory, path); if (file.exists()) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.IO_ERROR, "error: exported file ''{0}'' already exists!", file); throw new SVNException(err); } try { file.createNewFile(); } catch (IOException e) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.IO_ERROR, "error: cannot create new file ''{0}''", file); throw new SVNException(err); } }
private static void throwException(CoderResult result) throws SVNException { try { result.throwException(); } catch (CharacterCodingException e) { SVNErrorManager.error( SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e, SVNLogType.DEFAULT); } }
public static void abortTransaction(FSFS fsfs, String txnId) throws SVNException { File txnDir = fsfs.getTransactionDir(txnId); SVNFileUtil.deleteAll(txnDir, true); if (txnDir.exists()) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "Transaction cleanup failed"); SVNErrorManager.error(err, SVNLogType.FSFS); } }
public FSRevisionNode makeEntry( FSRevisionNode parent, String parentPath, String entryName, boolean isDir, String txnId) throws SVNException { if (!SVNPathUtil.isSinglePathComponent(entryName)) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.FS_NOT_SINGLE_PATH_COMPONENT, "Attempted to create a node with an illegal name ''{0}''", entryName); SVNErrorManager.error(err, SVNLogType.FSFS); } if (parent.getType() != SVNNodeKind.DIR) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.FS_NOT_DIRECTORY, "Attempted to create entry in non-directory parent"); SVNErrorManager.error(err, SVNLogType.FSFS); } if (!parent.getId().isTxn()) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.FS_NOT_MUTABLE, "Attempted to clone child of non-mutable node"); SVNErrorManager.error(err, SVNLogType.FSFS); } FSRevisionNode newRevNode = new FSRevisionNode(); newRevNode.setType(isDir ? SVNNodeKind.DIR : SVNNodeKind.FILE); String createdPath = SVNPathUtil.getAbsolutePath(SVNPathUtil.append(parentPath, entryName)); newRevNode.setCreatedPath(createdPath); newRevNode.setCopyRootPath(parent.getCopyRootPath()); newRevNode.setCopyRootRevision(parent.getCopyRootRevision()); newRevNode.setCopyFromRevision(SVNRepository.INVALID_REVISION); newRevNode.setCopyFromPath(null); FSID newNodeId = createNode(newRevNode, parent.getId().getCopyID(), txnId); FSRevisionNode childNode = myFSFS.getRevisionNode(newNodeId); FSTransactionRoot txnRoot = getTxnRoot(); txnRoot.setEntry(parent, entryName, childNode.getId(), newRevNode.getType()); return childNode; }
private void unlock12(Map pathToTokens, boolean force, ISVNLockHandler handler) throws SVNException { for (Iterator paths = pathToTokens.keySet().iterator(); paths.hasNext(); ) { String path = (String) paths.next(); String id = (String) pathToTokens.get(path); path = getRepositoryPath(path); if (id == null) { Object[] buffer = new Object[] {"get-lock", path}; write("(w(s))", buffer); authenticate(); read("[((?L))]", buffer, true); SVNLock lock = (SVNLock) buffer[0]; if (lock == null) { lock = new SVNLock(path, "", null, null, null, null); SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_NOT_LOCKED, "No lock on path ''{0}''", path); handler.handleUnlock(path, lock, err); continue; } id = lock.getID(); } Object[] buffer = new Object[] {"unlock", path, id, Boolean.valueOf(force)}; write("(w(s(s)w))", buffer); authenticate(); SVNErrorMessage error = null; try { read("[()]", buffer, true); } catch (SVNException e) { if (e.getErrorMessage() != null && e.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_LOCKED) { error = e.getErrorMessage(); error = SVNErrorMessage.create(error.getErrorCode(), error.getMessageTemplate(), path); } else { throw e; } } if (handler != null) { SVNLock lock = new SVNLock(path, id, null, null, null, null); handler.handleUnlock(path, lock, error); } } }
public static Date parseDateString(String str) throws SVNException { try { return parseDatestamp(str); } catch (SVNException svne) { throw svne; } catch (Throwable th) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.BAD_DATE); SVNErrorManager.error(err, th, SVNLogType.DEFAULT); } return NULL; }
/** * Called when a new directory has to be added. * * <p>For each 'addDir' call server will call 'closeDir' method after all children of the added * directory are added. * * <p>This implementation creates corresponding directory below root directory. */ public void addDir(String path, String copyFromPath, long copyFromRevision) throws SVNException { File newDir = new File(myRootDirectory, path); if (!newDir.exists()) { if (!newDir.mkdirs()) { SVNErrorMessage err = SVNErrorMessage.create( SVNErrorCode.IO_ERROR, "error: failed to add the directory ''{0}''.", newDir); throw new SVNException(err); } } Log.L.fine("dir added: " + path); }