Esempio n. 1
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;
  }
Esempio n. 2
0
  public DAVLock findLock(DAVResource resource, String lockToken) throws DAVException {
    // TODO: add here authz check later

    DAVLock davLock = null;
    FSLock lock = null;
    try {
      lock = (FSLock) resource.getLock();
    } catch (SVNException svne) {
      throw DAVException.convertError(
          svne.getErrorMessage(),
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Failed to look up lock by path.",
          null);
    }

    if (lock != null) {
      if (!lockToken.equals(lock.getID())) {
        throw new DAVException(
            "Incoming token doesn't match existing lock.",
            HttpServletResponse.SC_BAD_REQUEST,
            DAVErrorCode.LOCK_SAVE_LOCK);
      }
      davLock = convertSVNLockToDAVLock(lock, false, resource.exists());
      myOwner.setResponseHeader(
          HTTPHeader.CREATION_DATE_HEADER, SVNDate.formatDate(lock.getCreationDate()));
      myOwner.setResponseHeader(HTTPHeader.LOCK_OWNER_HEADER, lock.getOwner());
    }
    return davLock;
  }
Esempio n. 3
0
  public DAVLock getLock(DAVResource resource) throws DAVException {
    if (resource.getResourceURI().getPath() == null) {
      return null;
    }

    if (DAVHandlerFactory.METHOD_LOCK.equals(myOwner.getRequestMethod())) {
      return null;
    }

    // TODO: add authz check here later

    DAVLock davLock = null;
    FSLock lock = null;
    try {
      lock = (FSLock) resource.getLock();
    } catch (SVNException svne) {
      throw DAVException.convertError(
          svne.getErrorMessage(),
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Failed to check path for a lock.",
          null);
    }

    if (lock != null) {
      davLock = convertSVNLockToDAVLock(lock, myIsBreakLock, resource.exists());
      myOwner.setResponseHeader(
          HTTPHeader.CREATION_DATE_HEADER, SVNDate.formatDate(lock.getCreationDate()));
      myOwner.setResponseHeader(HTTPHeader.LOCK_OWNER_HEADER, lock.getOwner());
    }
    return davLock;
  }
Esempio n. 4
0
  public boolean hasLocks(DAVResource resource) throws DAVException {
    if (resource.getResourceURI().getPath() == null) {
      return false;
    }

    if (DAVHandlerFactory.METHOD_LOCK.equals(myOwner.getRequestMethod())) {
      return false;
    }

    // TODO: add authz check here later
    SVNLock lock = null;
    try {
      lock = resource.getLock();
    } catch (SVNException svne) {
      throw DAVException.convertError(
          svne.getErrorMessage(),
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Failed to check path for a lock.",
          null);
    }
    return lock != null;
  }
Esempio n. 5
0
  public void appendLock(DAVResource resource, DAVLock lock) throws DAVException {
    // TODO: add here authz check later
    FSFS fsfs = resource.getFSFS();
    String path = resource.getResourceURI().getPath();
    if (!resource.exists()) {
      SVNProperties revisionProps = new SVNProperties();
      revisionProps.put(SVNRevisionProperty.AUTHOR, resource.getUserName());
      DAVConfig config = resource.getRepositoryManager().getDAVConfig();
      if (resource.isSVNClient()) {
        throw new DAVException(
            "Subversion clients may not lock nonexistent paths.",
            HttpServletResponse.SC_METHOD_NOT_ALLOWED,
            DAVErrorCode.LOCK_SAVE_LOCK);
      } else if (!config.isAutoVersioning()) {
        throw new DAVException(
            "Attempted to lock non-existent path; turn on autoversioning first.",
            HttpServletResponse.SC_METHOD_NOT_ALLOWED,
            DAVErrorCode.LOCK_SAVE_LOCK);
      }

      long youngestRev = SVNRepository.INVALID_REVISION;
      try {
        youngestRev = resource.getLatestRevision();
      } catch (SVNException svne) {
        throw DAVException.convertError(
            svne.getErrorMessage(),
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            "Could not determine youngest revision",
            null);
      }

      FSTransactionInfo txnInfo = null;
      try {
        txnInfo = FSTransactionRoot.beginTransactionForCommit(youngestRev, revisionProps, fsfs);
      } catch (SVNException svne) {
        throw DAVException.convertError(
            svne.getErrorMessage(),
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            "Could not begin a transaction",
            null);
      }

      FSTransactionRoot root = null;
      try {
        root = fsfs.createTransactionRoot(txnInfo);
      } catch (SVNException svne) {
        throw DAVException.convertError(
            svne.getErrorMessage(),
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            "Could not begin a transaction",
            null);
      }

      FSCommitter committer =
          new FSCommitter(fsfs, root, txnInfo, resource.getLockTokens(), resource.getUserName());
      try {
        committer.makeFile(path);
      } catch (SVNException svne) {
        throw DAVException.convertError(
            svne.getErrorMessage(),
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            "Could not create empty file.",
            null);
      }

      try {
        DAVServletUtil.attachAutoRevisionProperties(txnInfo, path, fsfs);
      } catch (SVNException svne) {
        throw DAVException.convertError(
            svne.getErrorMessage(),
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            "Could not create empty file.",
            null);
      }

      StringBuffer conflictPath = new StringBuffer();
      try {
        committer.commitTxn(true, true, null, conflictPath);
      } catch (SVNException svne) {
        throw DAVException.convertError(
            svne.getErrorMessage(),
            HttpServletResponse.SC_CONFLICT,
            "Conflict when committing ''{0}''.",
            new Object[] {conflictPath.toString()});
      }
    }

    FSLock svnLock =
        convertDAVLockToSVNLock(
            lock, path, resource.isSVNClient(), ServletDAVHandler.getSAXParserFactory());
    try {
      fsfs.lockPath(
          path,
          svnLock.getID(),
          svnLock.getOwner(),
          svnLock.getComment(),
          svnLock.getExpirationDate(),
          myWorkingRevision,
          myIsStealLock,
          svnLock.isDAVComment());
    } catch (SVNException svne) {
      if (svne.getErrorMessage().getErrorCode() == SVNErrorCode.FS_NO_USER) {
        throw new DAVException(
            "Anonymous lock creation is not allowed.",
            HttpServletResponse.SC_UNAUTHORIZED,
            DAVErrorCode.LOCK_SAVE_LOCK);
      }
      throw DAVException.convertError(
          svne.getErrorMessage(),
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Failed to create new lock.",
          null);
    }

    myOwner.setResponseHeader(
        HTTPHeader.CREATION_DATE_HEADER, SVNDate.formatDate(svnLock.getCreationDate()));
    myOwner.setResponseHeader(HTTPHeader.LOCK_OWNER_HEADER, svnLock.getOwner());
    // TODO: add logging here later
  }