Beispiel #1
0
 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());
     }
   }
 }
Beispiel #2
0
  public static void main(String[] args) {
    /*
     * Initialize the library. It must be done before calling any
     * method of the library.
     */
    setupLibrary();

    /*
     * Run commit example and process error if any.
     */
    try {
      commitExample();
    } catch (SVNException e) {
      SVNErrorMessage err = e.getErrorMessage();
      /*
       * Display all tree of error messages.
       * Utility method SVNErrorMessage.getFullMessage() may be used instead of the loop.
       */
      while (err != null) {
        System.err.println(err.getErrorCode().getCode() + " : " + err.getMessage());
        err = err.getChildErrorMessage();
      }
      System.exit(1);
    }
    System.exit(0);
  }
 public Object invoke(File ws, VirtualChannel channel) throws IOException, InterruptedException {
   File workingCopy = new File(ws, location.getLocalDir()).getCanonicalFile();
   try {
     SVNURL svnUrl = SVNURL.parseURIEncoded(tagUrl);
     ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager();
     sam.setAuthenticationProvider(authProvider);
     SVNCopyClient copyClient = new SVNCopyClient(sam, null);
     buildListener.getLogger().println("[RELEASE] Creating subversion tag: " + tagUrl);
     SVNCopySource source =
         new SVNCopySource(SVNRevision.WORKING, SVNRevision.WORKING, workingCopy);
     SVNCommitInfo commitInfo =
         copyClient.doCopy(
             new SVNCopySource[] {source},
             svnUrl,
             false,
             true,
             true,
             commitMessage,
             new SVNProperties());
     SVNErrorMessage errorMessage = commitInfo.getErrorMessage();
     if (errorMessage != null) {
       throw new IOException("Failed to create tag: " + errorMessage.getFullMessage());
     }
     return null;
   } catch (SVNException e) {
     throw new IOException("Subversion tag creation failed: " + e.getMessage());
   }
 }
  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 Object invoke(File ws, VirtualChannel channel) throws IOException, InterruptedException {
   File workingCopy = new File(ws, location.getLocalDir()).getCanonicalFile();
   try {
     ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager();
     sam.setAuthenticationProvider(authProvider);
     SVNCommitClient commitClient = new SVNCommitClient(sam, null);
     buildListener.getLogger().println("[RELEASE] " + commitMessage);
     debuggingLogger.fine(String.format("Committing working copy: '%s'", workingCopy));
     SVNCommitInfo commitInfo =
         commitClient.doCommit(
             new File[] {workingCopy},
             true,
             commitMessage,
             null,
             null,
             true,
             true,
             SVNDepth.INFINITY);
     SVNErrorMessage errorMessage = commitInfo.getErrorMessage();
     if (errorMessage != null) {
       throw new IOException("Failed to commit working copy: " + errorMessage.getFullMessage());
     }
     return null;
   } catch (SVNException e) {
     throw new IOException(e.getMessage());
   }
 }
Beispiel #6
0
 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;
 }
Beispiel #7
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;
  }
  public DAVLock refreshLock(DAVResource resource, String lockToken, Date newTime)
      throws DAVException {
    // TODO: add here authz check
    FSFS fsfs = resource.getFSFS();
    String path = resource.getResourceURI().getPath();

    FSLock svnLock = null;
    try {
      svnLock = (FSLock) fsfs.getLockHelper(path, false);
    } catch (SVNException e) {
      throw DAVException.convertError(
          e.getErrorMessage(),
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Token doesn't point to a lock.",
          null);
    }

    if (svnLock == null || !svnLock.getID().equals(lockToken)) {
      throw new DAVException(
          "Lock refresh request doesn't match existing lock.",
          HttpServletResponse.SC_UNAUTHORIZED,
          DAVErrorCode.LOCK_SAVE_LOCK);
    }

    try {
      svnLock =
          (FSLock)
              fsfs.lockPath(
                  svnLock.getPath(),
                  svnLock.getID(),
                  resource.getUserName(),
                  svnLock.getComment(),
                  newTime,
                  SVNRepository.INVALID_REVISION,
                  true,
                  svnLock.isDAVComment());
    } catch (SVNException e) {
      SVNErrorMessage err = e.getErrorMessage();
      if (err.getErrorCode() == SVNErrorCode.FS_NO_USER) {
        throw new DAVException(
            "Anonymous lock refreshing is not allowed.",
            HttpServletResponse.SC_UNAUTHORIZED,
            DAVErrorCode.LOCK_SAVE_LOCK);
      }
      throw DAVException.convertError(
          err,
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Failed to refresh existing lock.",
          null);
    }
    return convertSVNLockToDAVLock(svnLock, false, resource.exists());
  }
  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;
  }
Beispiel #10
0
  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 void safeRevertTag(String tagUrl, String commitMessageSuffix) {
   try {
     log("Reverting subversion tag: " + tagUrl);
     SVNURL svnUrl = SVNURL.parseURIEncoded(tagUrl);
     SVNCommitClient commitClient = new SVNCommitClient(createAuthenticationManager(), null);
     SVNCommitInfo commitInfo =
         commitClient.doDelete(new SVNURL[] {svnUrl}, COMMENT_PREFIX + commitMessageSuffix);
     SVNErrorMessage errorMessage = commitInfo.getErrorMessage();
     if (errorMessage != null) {
       log("Failed to revert '" + tagUrl + "': " + errorMessage.getFullMessage());
     }
   } catch (SVNException e) {
     log("Failed to revert '" + tagUrl + "': " + e.getLocalizedMessage());
   }
 }
Beispiel #12
0
 public static void sendError(
     @NotNull SvnServerWriter writer, @NotNull SVNErrorMessage errorMessage) throws IOException {
   writer
       .listBegin()
       .word("failure")
       .listBegin()
       .listBegin()
       .number(errorMessage.getErrorCode().getCode())
       .string(errorMessage.getMessage())
       .string("")
       .number(0)
       .listEnd()
       .listEnd()
       .listEnd();
 }
Beispiel #13
0
  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 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;
 }
  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);
  }
    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);
    }
 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 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 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);
 }
Beispiel #21
0
  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 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);
 }
Beispiel #23
0
 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);
   }
 }
Beispiel #24
0
  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;
  }
  /**
   * 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 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;
 }
 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;
 }
Beispiel #28
0
 /**
  * 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);
   }
 }
Beispiel #29
0
 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);
   }
 }
Beispiel #30
0
 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);
   }
 }