Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]
Return to module

File Contents

Contents of /Subversion-0.112/fs.c:

/* ================================================================
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowledgment: "This product includes
 * software developed by CollabNet (http://www.Collab.Net/)."
 * Alternately, this acknowledgment may appear in the software itself, if
 * and wherever such third-party acknowledgments normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */


#include "svnmod.h"

#include <svn_fs.h>
#include <svn_path.h>

/*! @module Subversion */

/*! @module FileSystem
 *!
 *!  The FileSystem submodule provides direct access to the filesystem
 *!  layer of Subversion.
 */


/*! @decl void delete_fs( string path )
 *!
 *!  Delete the filesystem at @[path].
 */
static void f_delete_fs (INT32 args)
{
  apr_pool_t *pool;
  svn_error_t *err;
  struct pike_string *path;

  get_all_args ("delete_fs", args, "%W", &path);

  path = svn_pike_to_utf8 (path);

  pool = svn_pool_create (NULL);

  THREADS_ALLOW ();

  err = svn_fs_delete_fs (APR_STR0 (path), pool);

  THREADS_DISALLOW ();

  if (err)
    svn_pike_set_error (err);

  apr_pool_destroy (pool);

  do_free_string (path);

  if (err)
    pike_throw ();
  else
    pop_n_elems (args);
}


/*! @decl void hotcopy( string src_path, string dest_path, int|void clean  )
 *!
 *!  Copy a possibly live Subversion filesystem from @[src_path] to
 *!  @[dest_path].  If @[clean] is non-zero, perform cleanup on the
 *!  source filesystem as part of the copy operation; currently, this
 *!  means deleting copied, unused logfiles for a Berkeley DB source
 *!  filesystem.
 */
static void f_hotcopy (INT32 args)
{
  apr_pool_t *pool;
  svn_error_t *err;
  struct pike_string *src_path, *dest_path;
  svn_boolean_t clean;

  get_all_args ("hotcopy", args, "%W%W", &src_path, &dest_path);
  clean = svn_pike_check_force_arg ("hotcopy", args, 2);

  src_path = svn_pike_to_utf8 (src_path);
  dest_path = svn_pike_to_utf8 (dest_path);

  pool = svn_pool_create (NULL);

  THREADS_ALLOW ();

  err = svn_fs_hotcopy (APR_STR0 (src_path), APR_STR0 (dest_path), clean, pool);

  THREADS_DISALLOW ();

  if (err)
    svn_pike_set_error (err);

  apr_pool_destroy (pool);

  do_free_string (src_path);
  do_free_string (dest_path);

  if (err)
    pike_throw ();
  else
    pop_n_elems (args);
}


/*! @decl void berkeley_recover( string path )
 *!
 *!  Perform any necessary non-catastrophic recovery on a Berkeley
 *!  DB-based Subversion filesystem, stored in the environment @[path].
 *!
 *!  After an unexpected server exit, due to a server crash or a system
 *!  crash, a Subversion filesystem based on Berkeley DB needs to run
 *!  recovery procedures to bring the database back into a consistent
 *!  state and release any locks that were held by the deceased process.
 *!  The recovery procedures require exclusive access to the database
 *!  --- while they execute, no other process or thread may access the
 *!  database.
 *!
 *!  In a server with multiple worker processes, like Apache, if a
 *!  worker process accessing the filesystem dies, you must stop the
 *!  other worker processes, and run recovery.  Then, the other worker
 *!  processes can re-open the database and resume work.
 *!
 *!  If the server exited cleanly, there is no need to run recovery, but
 *!  there is no harm in it, either, and it take very little time.  So
 *!  it's a fine idea to run recovery when the server process starts,
 *!  before it begins handling any requests.
 */
static void f_berkeley_recover (INT32 args)
{
  apr_pool_t *pool;
  svn_error_t *err;
  struct pike_string *path;

  get_all_args ("berkeley_recover", args, "%W", &path);

  path = svn_pike_to_utf8 (path);

  pool = svn_pool_create (NULL);

  THREADS_ALLOW ();

  err = svn_fs_berkeley_recover (APR_STR0 (path), pool);

  THREADS_DISALLOW ();

  if (err)
    svn_pike_set_error (err);

  apr_pool_destroy (pool);

  do_free_string (path);

  if (err)
    pike_throw ();
  else
    pop_n_elems (args);
}


/*! @decl array(string) berkeley_logfiles( string path, int|void only_unused  )
 *!
 *!  Return an array of log file names of Berkeley DB-based Subversion
 *!  filesystem.
 *!
 *!  This function wraps the Berkeley DB 'log_archive' function
 *!  called by the db_archive binary.  Repository administrators may
 *!  want to run this function periodically and delete the unused log
 *!  files, as a way of reclaiming disk space.
 *!
 *! @param only_unused
 *!   If non-zero, the result will contain only the names of Berkeley DB
 *!   log files still in use by the filesystem.  Otherwise, all log files 
 *!   (used and unused) are returned.
 */
static void f_berkeley_logfiles (INT32 args)
{
  apr_pool_t *pool;
  svn_error_t *err;
  struct pike_string *path;
  svn_boolean_t only_unused;
  apr_array_header_t *arr;
  struct svalue ret;

  get_all_args ("berkeley_logfiles", args, "%W", &path);
  only_unused = svn_pike_check_force_arg ("berkeley_logfiles", args, 1);

  path = svn_pike_to_utf8 (path);

  pool = svn_pool_create (NULL);

  THREADS_ALLOW ();

  err = svn_fs_berkeley_logfiles (&arr, APR_STR0 (path), only_unused, pool);

  THREADS_DISALLOW ();

  if (err)
    svn_pike_set_error (err);
  else if(arr) {
    const char **files = (const char **) arr->elts;
    int i;
    for (i=0; i<arr->nelts; i++) {
      push_text (files[i]);
      f_utf8_to_string (1);
    }
    f_aggregate(arr->nelts);
    ret = *--Pike_sp;  
  } else {
    ret.u.integer = 0;
    ret.type = PIKE_T_INT;
    ret.subtype = NUMBER_UNDEFINED;
  }

  apr_pool_destroy (pool);

  do_free_string (path);

  if (err)
    pike_throw ();
  else {
    pop_n_elems (args);
    *Pike_sp++ = ret;
  }
}


/*! @decl Version version( )
 *!
 *!  Get libsvn_fs version information.
 */
static void f_version (INT32 args)
{
  pop_n_elems (args);
  svn_pike_push_version (svn_fs_version ());
}


/* Initialize FS submodule */

void svn_pike_init_fs (void)
{
  struct program *fs_program;
  struct svalue prog;
  prog.type = PIKE_T_PROGRAM;
  prog.subtype = 0;

  start_new_program ();

  ADD_FUNCTION ("delete_fs", f_delete_fs, tFunc (tStr, tVoid), 0);
  ADD_FUNCTION ("hotcopy", f_hotcopy, tFunc (tStr tStr tOr(tInt, tVoid),
					     tVoid), 0);
  ADD_FUNCTION ("berkeley_recover", f_berkeley_recover, tFunc (tStr, tVoid),
		0);
  ADD_FUNCTION ("berkeley_logfiles", f_berkeley_logfiles,
		tFunc (tStr tOr (tInt, tVoid), tArr (tStr)), 0);
  ADD_FUNCTION ("version", f_version, tFunc (tNone, tObj), 0);

  fs_program = end_program ();
  add_object_constant ("FileSystem", clone_object (fs_program, 0), 0);
  free_program (fs_program);
}

/*! @endmodule */
/*! @endmodule */

gotpike.org | Copyright © 2004 - 2011 | Pike is a trademark of Department of Computer and Information Science, Linköping University