[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: locking hook scripts help

From: John <jsparrow_at_ecclescollege.ac.uk>
Date: 2005-07-26 09:33:36 CEST

Phil <plabonte <at> gmail.com> writes:

> I read in the manual that we can make a hook script, from the current
> existing scripts, that would only allow the creator of a lock to be
> the one to break the lock, or an administrator.
>
> I need help modifying the scripts to have Subversion work that way.

Hi Phil, hows this? Uses Perl bindings. The allowbreak array is a list of people
who can break and steal any locks. Otherwise only the owner of a lock can mess
with it. (for speed, if your in the allowbreak array it doesn't even query the
lock, no need).

I'm a perl novice, so others may have improvements to suggest.

Then I but the following in pre-lock.cmd and pre-unlock.cmd:

@echo off

cd \Repos
\perl\bin\perl check-lock.pl %1 %2 %3
if errorlevel 1 goto :ERROR
exit 0

:ERROR
echo Error 1>&2
exit 1

==============================

# this is check-lock.pl

use strict;
use warnings;

use File::Basename;

use SVN::Core;
use SVN::Fs;
use SVN::Repos;

my @allowbreak = ("John","Jane");

my $paramrepo;
my $parampath;
my $paramuser;
my $pool;

&usage unless @ARGV == 3;

$paramrepo = shift;
$parampath = shift;
$paramuser = shift;

unless (-e $paramrepo)
{
        &usage("$0: repository directory `$paramrepo' does not exist.");
}
unless (-d $paramrepo)
{
        &usage("$0: repository directory `$paramrepo' is not a directory.");
}

foreach my $breakuser (@allowbreak)
{
        if ($paramuser eq $breakuser)
        {
                # you're a special kinda guy
                exit 0;
        }
}

my $repo = SVN::Repos::open($paramrepo);
my $fs = $repo->fs;
my $lock = SVN::_Fs::svn_fs_get_lock($fs,$parampath,$pool);

if ($lock)
{
        my $owner = SVN::_Core::svn_lock_t_owner_get($lock);
        if ($owner eq $paramuser)
        {
                # You own it anyway
                exit 0;
        } else
        {
                # Not allowed
                print STDERR "You cannot break a lock owned by '$owner'";
                exit 1;
        }
}

# no lock, so allow it
exit 0;

sub usage
{
  warn "@_\n" if @_;
  die "usage: $0 REPOS PATHINREPOS USER\n";
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Tue Jul 26 09:36:04 2005

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.