Alien-SVN

 view release on metacpan or  search on metacpan

src/subversion/subversion/bindings/javahl/native/SVNRepos.cpp  view on Meta::CPAN

/**
 * @copyright
 * ====================================================================
 *    Licensed to the Apache Software Foundation (ASF) under one
 *    or more contributor license agreements.  See the NOTICE file
 *    distributed with this work for additional information
 *    regarding copyright ownership.  The ASF licenses this file
 *    to you under the Apache License, Version 2.0 (the
 *    "License"); you may not use this file except in compliance
 *    with the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing,
 *    software distributed under the License is distributed on an
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *    KIND, either express or implied.  See the License for the
 *    specific language governing permissions and limitations
 *    under the License.
 * ====================================================================
 * @endcopyright
 *
 * @file SVNRepos.cpp
 * @brief Implementation of the class SVNRepos
 */

#include "SVNRepos.h"
#include "CreateJ.h"
#include "ReposNotifyCallback.h"
#include "JNIUtil.h"
#include "svn_error_codes.h"
#include "svn_repos.h"
#include "svn_config.h"
#include "svn_props.h"
#include "svn_pools.h"
#include "svn_path.h"
#include "svn_utf.h"
#include "svn_private_config.h"

SVNRepos::SVNRepos()
    : m_cancelOperation(false)
{
}

SVNRepos::~SVNRepos()
{
}

SVNRepos *SVNRepos::getCppObject(jobject jthis)
{
  static jfieldID fid = 0;
  jlong cppAddr = SVNBase::findCppAddrForJObject(jthis, &fid,
                                                 JAVA_PACKAGE"/SVNRepos");
  return (cppAddr == 0 ? NULL : reinterpret_cast<SVNRepos *>(cppAddr));
}

void SVNRepos::dispose(jobject jthis)
{
  static jfieldID fid = 0;
  SVNBase::dispose(jthis, &fid, JAVA_PACKAGE"/SVNRepos");
}

void SVNRepos::cancelOperation()
{
  m_cancelOperation = true;
}

svn_error_t *
SVNRepos::checkCancel(void *cancelBaton)
{
  SVNRepos *that = static_cast<SVNRepos *>(cancelBaton);
  if (that->m_cancelOperation)
    return svn_error_create(SVN_ERR_CANCELLED, NULL,
                            _("Operation cancelled"));
  else
    return SVN_NO_ERROR;
}

void SVNRepos::create(File &path, bool disableFsyncCommits,
                      bool keepLogs, File &configPath,
                      const char *fstype)
{
  SVN::Pool requestPool;
  svn_repos_t *repos;
  apr_hash_t *config;
  apr_hash_t *fs_config = apr_hash_make(requestPool.getPool());

  if (path.isNull())
    {
      JNIUtil::throwNullPointerException("path");
      return;
    }

  apr_hash_set(fs_config, SVN_FS_CONFIG_BDB_TXN_NOSYNC,
               APR_HASH_KEY_STRING,
               (disableFsyncCommits? "1" : "0"));

src/subversion/subversion/bindings/javahl/native/SVNRepos.cpp  view on Meta::CPAN

                  (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
                   _("Revisions must not be greater than the youngest revision"
                     " (%ld)"), youngest), );
    }

  SVN_JNI_ERR(svn_repos_dump_fs3(repos, dataOut.getStream(requestPool),
                                 lower, upper, incremental, useDeltas,
                                 notifyCallback != NULL
                                    ? ReposNotifyCallback::notify
                                    : NULL,
                                 notifyCallback,
                                 checkCancel, this, requestPool.getPool()), );
}

void SVNRepos::hotcopy(File &path, File &targetPath,
                       bool cleanLogs, bool incremental)
{
  SVN::Pool requestPool;

  if (path.isNull())
    {
      JNIUtil::throwNullPointerException("path");
      return;
    }

  if (targetPath.isNull())
    {
      JNIUtil::throwNullPointerException("targetPath");
      return;
    }

  SVN_JNI_ERR(svn_repos_hotcopy2(path.getInternalStyle(requestPool),
                                 targetPath.getInternalStyle(requestPool),
                                 cleanLogs, incremental,
                                 checkCancel, this /* cancel callback/baton */,
                                 requestPool.getPool()),
             );
}

static void
list_dblogs(File &path, MessageReceiver &receiver, bool only_unused)
{
  SVN::Pool requestPool;
  apr_array_header_t *logfiles;

  if (path.isNull())
    {
      JNIUtil::throwNullPointerException("path");
      return;
    }

  SVN_JNI_ERR(svn_repos_db_logfiles(&logfiles,
                                    path.getInternalStyle(requestPool),
                                    only_unused, requestPool.getPool()), );

  /* Loop, printing log files.  We append the log paths to the
   * repository path, making sure to return everything to the native
   * style and encoding before printing. */
  for (int i = 0; i < logfiles->nelts; ++i)
    {
      const char *log_utf8;
      log_utf8 = svn_dirent_join(path.getInternalStyle(requestPool),
                                 APR_ARRAY_IDX(logfiles, i, const char *),
                                 requestPool.getPool());
      log_utf8 = svn_dirent_local_style(log_utf8, requestPool.getPool());
      receiver.receiveMessage(log_utf8);
    }
}

void SVNRepos::listDBLogs(File &path, MessageReceiver &messageReceiver)
{
  list_dblogs(path, messageReceiver, false);
}

void SVNRepos::listUnusedDBLogs(File &path,
                                MessageReceiver &messageReceiver)
{
  list_dblogs(path, messageReceiver, true);
}

void SVNRepos::load(File &path,
                    InputStream &dataIn,
                    Revision &revisionStart,
                    Revision &revisionEnd,
                    bool ignoreUUID,
                    bool forceUUID,
                    bool usePreCommitHook,
                    bool usePostCommitHook,
                    const char *relativePath,
                    ReposNotifyCallback *notifyCallback)
{
  SVN::Pool requestPool;
  svn_repos_t *repos;
  svn_revnum_t lower = SVN_INVALID_REVNUM, upper = SVN_INVALID_REVNUM;
  enum svn_repos_load_uuid uuid_action = svn_repos_load_uuid_default;
  if (ignoreUUID)
    uuid_action = svn_repos_load_uuid_ignore;
  else if (forceUUID)
    uuid_action = svn_repos_load_uuid_force;

  if (path.isNull())
    {
      JNIUtil::throwNullPointerException("path");
      return;
    }

  /* ### We only handle revision numbers right now, not dates. */
  if (revisionStart.revision()->kind == svn_opt_revision_number)
    lower = revisionStart.revision()->value.number;
  if (revisionEnd.revision()->kind == svn_opt_revision_number)
    upper = revisionEnd.revision()->value.number;
  if (upper < lower
      && lower != SVN_INVALID_REVNUM
      && upper != SVN_INVALID_REVNUM)
    {
      SVN_JNI_ERR(svn_error_create
                  (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
                   _("First revision cannot be higher than second")), );
    }

  SVN_JNI_ERR(svn_repos_open2(&repos, path.getInternalStyle(requestPool),
                              NULL, requestPool.getPool()), );

  SVN_JNI_ERR(svn_repos_load_fs4(repos, dataIn.getStream(requestPool),
                                 lower, upper, uuid_action, relativePath,
                                 usePreCommitHook, usePostCommitHook,

src/subversion/subversion/bindings/javahl/native/SVNRepos.cpp  view on Meta::CPAN

    }

  SVN_JNI_ERR(svn_repos_open2(&repos, path.getInternalStyle(requestPool),
                              NULL, requestPool.getPool()), NULL);
  /* Fetch all locks on or below the root directory. */
  SVN_JNI_ERR(svn_repos_fs_get_locks2(&locks, repos, "/", depth, NULL, NULL,
                                      requestPool.getPool()),
              NULL);

  JNIEnv *env = JNIUtil::getEnv();
  jclass clazz = env->FindClass(JAVA_PACKAGE"/types/Lock");
  if (JNIUtil::isJavaExceptionThrown())
    return NULL;

  std::vector<jobject> jlocks;

  for (hi = apr_hash_first(requestPool.getPool(), locks);
       hi;
       hi = apr_hash_next(hi))
    {
      void *val;
      apr_hash_this(hi, NULL, NULL, &val);
      svn_lock_t *lock = reinterpret_cast<svn_lock_t *>(val);
      jobject jLock = CreateJ::Lock(lock);

      jlocks.push_back(jLock);
    }

  env->DeleteLocalRef(clazz);

  return CreateJ::Set(jlocks);
}

void SVNRepos::rmlocks(File &path, StringArray &locks)
{
  SVN::Pool requestPool;
  svn_repos_t *repos;
  svn_fs_t *fs;
  svn_fs_access_t *access;

  if (path.isNull())
    {
      JNIUtil::throwNullPointerException("path");
      return;
    }

  SVN_JNI_ERR(svn_repos_open2(&repos, path.getInternalStyle(requestPool),
                              NULL, requestPool.getPool()), );
  fs = svn_repos_fs(repos);
  const char *username = NULL;

  /* svn_fs_unlock() demands that some username be associated with the
   * filesystem, so just use the UID of the person running 'svnadmin'.*/
  {
    apr_uid_t uid;
    apr_gid_t gid;
    char *un;
    if (apr_uid_current(&uid, &gid, requestPool.getPool()) == APR_SUCCESS &&
        apr_uid_name_get(&un, uid, requestPool.getPool()) == APR_SUCCESS)
      {
        svn_error_t *err = svn_utf_cstring_to_utf8(&username, un,
                                                   requestPool.getPool());
        svn_error_clear(err);
        if (err)
          username = "administrator";
      }
  }

  /* Create an access context describing the current user. */
  SVN_JNI_ERR(svn_fs_create_access(&access, username, requestPool.getPool()), );

  /* Attach the access context to the filesystem. */
  SVN_JNI_ERR(svn_fs_set_access(fs, access), );

  SVN::Pool subpool;
  const apr_array_header_t *args = locks.array(requestPool);
  for (int i = 0; i < args->nelts; ++i)
    {
      const char *lock_path = APR_ARRAY_IDX(args, i, const char *);
      svn_lock_t *lock;

      /* Fetch the path's svn_lock_t. */
      svn_error_t *err = svn_fs_get_lock(&lock, fs, lock_path, subpool.getPool());
      if (err)
        goto move_on;
      if (! lock)
        continue;

      /* Now forcibly destroy the lock. */
      err = svn_fs_unlock(fs, lock_path,
                          lock->token, 1 /* force */, subpool.getPool());
      if (err)
        goto move_on;

    move_on:
      svn_error_clear(err);
      subpool.clear();
    }

  return;
}



( run in 0.689 second using v1.01-cache-2.11-cpan-4991d5b9bd9 )