LfsLockResponse deleteLock()

in src/main/java/com/googlesource/gerrit/plugins/lfs/locks/LfsLocksHandler.java [85:108]


  LfsLockResponse deleteLock(
      Project.NameKey project, CurrentUser user, String lockId, LfsDeleteLockInput input)
      throws LfsException {
    log.atFine().log(
        "Delete (-f %s) lock for %s in project %s",
        Boolean.TRUE.equals(input.force), lockId, project);
    LfsProjectLocks locks = projectLocks.getUnchecked(project);
    Optional<LfsLock> hasLock = locks.getLock(lockId);
    if (!hasLock.isPresent()) {
      throw new LfsException(
          String.format("there is no lock id %s in project %s", lockId, project));
    }

    LfsLock lock = hasLock.get();
    Optional<String> username = user.getUserName();
    if ((username.isPresent() && lock.owner.name.equals(username.get()))
        || Boolean.TRUE.equals(input.force)) {
      locks.deleteLock(lock);
      return new LfsLockResponse(lock);
    }

    throw new LfsException(
        String.format("Lock %s is owned by different user %s", lockId, lock.owner.name));
  }