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);
  }
Beispiel #2
0
  @Test
  public void testCommitOfLockedFile() throws SVNException {
    final String fullFilePath = "Project/Prueba/Modify/prueba.txt";
    final String filePath = "Prueba/Modify/prueba.txt";

    final TestOptions options = TestOptions.getInstance();
    final Sandbox sandbox =
        Sandbox.createWithCleanup(getClass().getSimpleName() + ".testModifyLocked", options);
    final SVNURL url = sandbox.createSvnRepository();
    final CommitBuilder commitBuilder = new CommitBuilder(url);
    commitBuilder.addFile(fullFilePath);
    commitBuilder.commit();

    // user paths relative to Project directory.

    SVNRepository repository = SVNRepositoryFactory.create(url.appendPath("Project", false));
    repository.setAuthenticationManager(new BasicAuthenticationManager("user", "password"));
    final Map<String, Long> pathsToRevisions = new HashMap<String, Long>();
    pathsToRevisions.put(filePath, 1l);
    repository.lock(pathsToRevisions, null, false, null);

    repository.closeSession();
    // same user as one who owns the lock.
    repository.setAuthenticationManager(new BasicAuthenticationManager("user", "password"));

    final SVNLock lock = repository.getLock(filePath);
    Assert.assertNotNull(lock);
    Assert.assertNotNull(lock.getID());
    Assert.assertEquals("user", lock.getOwner());

    final Map<String, String> locks = new HashMap<String, String>();

    try {
      tryCommit(filePath, repository, locks);
      Assert.fail();
    } catch (SVNException e) {
      // no lock token.
    }

    locks.put(filePath, lock.getID());
    SVNCommitInfo info = tryCommit(filePath, repository, locks);
    Assert.assertNotNull(info);
    Assert.assertEquals(2, info.getNewRevision());
  }