1

We are running VisualSVN on Windows 2012. I have been tasked with preventing the stealing of locks. I want to use a pre-unlock hook. To start, I want to compare the lock owner's name to the lock-breaking user's name. I can find the lock owner on the server with svnlook:

svnlook lock C:\Repositories\DIT_TEST time-for-a-sandwich.txt

That gives me a little list of info that includes the owner. Cool.

I want to replicate that in SharpSVN. Here's what I have so far:

using (SvnClient client = new SvnClient())
{
    StringBuilder sbLockOwner = new StringBuilder();
    Collection<SvnListEventArgs> col;
    if (client.GetList(new Uri("https://dit-visualsvn/svn/DIT_TEST"), out col))
    {
        foreach (SvnListEventArgs svnListEventArg in col)
        {
            sbLockOwner.Append(svnListEventArg.Lock.Owner.ToString());
        }
    }
}

When I try to release a lock, I get the error:

Unable to connect to a repository at URL 'https://dit-visualsvn/svn/DIT_TEST' --->
Access to '/svn/DIT_TEST' forbidden.

I have verified that my user has read/write permission for the repository and I've tried using the client.Authentication.ForceCredentials("login", "pswd"); solution. Still not allowed.

How can I get the lock owner's name with SharpSVN?

More info: If I change my code to the response on this SO, I still see that access is forbidden.

Community
  • 1
  • 1
mrcoulson
  • 1,331
  • 6
  • 20
  • 35

1 Answers1

0

If you want to replicate 'svnlook' using SharpSvn, you should start by looking at the SvnLookClient.

I'm guessing that you are using Windows/integrated security with your visualsvn server and that is (in general) not going to work from a server process that runs under different credentials. But when you are in a repository hook you don't need credentials as you have access to the physical files.

But then you hit the problem that svnlook lock isn't implemented on the SvnLookClient yet...

At that point I usually start looking at svnadmin commands, to see if there are equivalents there as svnlook and svnadmin work on the same layer. In this case you would find svnadmin lslocks, svnadmin lock and svnadmin unlock... But continuing the search on the SharpSvn's svnadmin-like SvnRepositoryClient you don't find these commands either.


And at that point I switched to a different answer mode. The feature wasn't in SharpSvn yet. But as of now it is available in the last SharpSvn build.


You should now be able to use

void Main(string[] args)
{
   SvnHookArguments ha;
   if (!SvnHookArguments.ParseHookArguments(args, SvnHookType.PreUnlock, Console.In, out ha)
   {
       Console.Error.Writeline("Bad arguments");
       Environment.Exit(1);
   }
   using (SvnLookClient look = new SvnLookClient())
   {
       SvnLockInfo lck;
       look.GetLock(ha.LookOrigin, ha.Path, out lck);

       if (lck == null)
           return; // Wasn't locked???

       // lck.Owner now contains the old owner
       // ha.User the new user
   }
}

But I'm guessing you also want to implement a .PreLock hook, as I usually break locks when obtaining the lock myself... not by unlocking.

Bert Huijben
  • 19,525
  • 4
  • 57
  • 73
  • This looks promising. I'll be trying the new version today. And yeah, maybe I do need to do a prelock hook. Basically, we have team members who want me to disable the stealing of locks. – mrcoulson Nov 13 '15 at 12:36
  • I've been trying to use this and I keep getting the error that `the located assembly's manifest defintion does not match the assembly reference.` I've removed and re-added it to different projects and I always seem to come up with that. I may still be doing something wrong, but I was curious if you were aware of any such issue. – mrcoulson Nov 17 '15 at 16:01
  • Without the actual error message it is hard to guess what causes this. It looks like an assembly mismatch, but it is easy to cause problems like this by not installing the right Visual C++ runtime. Depending on the SharpSvn build this could be the VS2008 or VS2010, x86 or x64 version. You need the VS2008 versions if you use the .Net 2.0+ assembly, while you need the VS2010 version if you use the .Net 4.0+ assembly. If you use the 2.0+ version in a .Net 4.0+ setup you need a specific config option in your application config file (as noted by the error message). – Bert Huijben Nov 19 '15 at 09:08