subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmpil...@apache.org
Subject svn commit: r1228371 - in /subversion/trunk/subversion: svnadmin/main.c tests/cmdline/svnadmin_tests.py tests/cmdline/svntest/main.py
Date Fri, 06 Jan 2012 19:50:30 GMT
Author: cmpilato
Date: Fri Jan  6 19:50:30 2012
New Revision: 1228371

URL: http://svn.apache.org/viewvc?rev=1228371&view=rev
Log:
Finish issue #4092 ("Add 'svnadmin unlock' subcommand which provides a
lock token for unlock validation").

* subversion/svnadmin/main.c
  (cmd_table): Add new "unlock" function.
  (subcommand_unlock): New function.

* subversion/tests/cmdline/svntest/main.py
  (get_pre_unlock_hook_path): New function.

* subversion/tests/cmdline/svnadmin_tests.py
  (locking): Expand testing to cover uses of 'svnadmin unlock'.

Modified:
    subversion/trunk/subversion/svnadmin/main.c
    subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py
    subversion/trunk/subversion/tests/cmdline/svntest/main.py

Modified: subversion/trunk/subversion/svnadmin/main.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svnadmin/main.c?rev=1228371&r1=1228370&r2=1228371&view=diff
==============================================================================
--- subversion/trunk/subversion/svnadmin/main.c (original)
+++ subversion/trunk/subversion/svnadmin/main.c Fri Jan  6 19:50:30 2012
@@ -163,6 +163,7 @@ static svn_opt_subcommand_t
   subcommand_setlog,
   subcommand_setrevprop,
   subcommand_setuuid,
+  subcommand_unlock,
   subcommand_upgrade,
   subcommand_verify;
 
@@ -435,6 +436,13 @@ static const svn_opt_subcommand_desc2_t 
     "generate a brand new UUID for the repository.\n"),
    {0} },
 
+  {"unlock", subcommand_unlock, {0}, N_
+   ("usage: svnadmin unlock REPOS_PATH LOCKED_PATH USERNAME TOKEN\n\n"
+    "Unlocked LOCKED_PATH (as USERNAME) after verifying that the token\n"
+    "associated with the lock matches TOKEN.  Use --bypass-hooks to avoid\n"
+    "triggering the pre- and post-unlock hook scripts.\n"),
+   {svnadmin__bypass_hooks} },
+
   {"upgrade", subcommand_upgrade, {0}, N_
    ("usage: svnadmin upgrade REPOS_PATH\n\n"
     "Upgrade the repository located at REPOS_PATH to the latest supported\n"
@@ -1654,6 +1662,47 @@ subcommand_rmlocks(apr_getopt_t *os, voi
 
 /* This implements `svn_opt_subcommand_t'. */
 static svn_error_t *
+subcommand_unlock(apr_getopt_t *os, void *baton, apr_pool_t *pool)
+{
+  struct svnadmin_opt_state *opt_state = baton;
+  svn_repos_t *repos;
+  svn_fs_t *fs;
+  svn_fs_access_t *access;
+  apr_array_header_t *args;
+  const char *username;
+  const char *lock_path;
+  const char *lock_path_utf8;
+  const char *lock_token = NULL;
+
+  /* Expect three more arguments: PATH USERNAME TOKEN */
+  SVN_ERR(parse_args(&args, os, 3, 3, pool));
+  lock_path = APR_ARRAY_IDX(args, 0, const char *);
+  username = APR_ARRAY_IDX(args, 1, const char *);
+  lock_token = APR_ARRAY_IDX(args, 2, const char *);
+
+  /* Open the repos/FS, and associate an access context containing
+     USERNAME. */
+  SVN_ERR(open_repos(&repos, opt_state->repository_path, pool));
+  fs = svn_repos_fs(repos);
+  SVN_ERR(svn_fs_create_access(&access, username, pool));
+  SVN_ERR(svn_fs_set_access(fs, access));
+
+  SVN_ERR(svn_utf_cstring_to_utf8(&lock_path_utf8, lock_path, pool));
+  if (opt_state->bypass_hooks)
+    SVN_ERR(svn_fs_unlock(fs, lock_path_utf8, lock_token,
+                          FALSE, pool));
+  else
+    SVN_ERR(svn_repos_fs_unlock(repos, lock_path_utf8, lock_token,
+                                FALSE, pool));
+
+  SVN_ERR(svn_cmdline_printf(pool, _("'%s' unlocked by user '%s'.\n"),
+                             lock_path, username));
+  return SVN_NO_ERROR;
+}
+
+
+/* This implements `svn_opt_subcommand_t'. */
+static svn_error_t *
 subcommand_upgrade(apr_getopt_t *os, void *baton, apr_pool_t *pool)
 {
   svn_error_t *err;

Modified: subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py?rev=1228371&r1=1228370&r2=1228371&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svnadmin_tests.py Fri Jan  6 19:50:30 2012
@@ -1711,18 +1711,69 @@ def locking(sbox):
                                           "A/D/G/rho", "jrandom",
                                           comment_path, lock_token)
 
+  # Test unlocking a patch with the wrong token.
+  expected_error = ".*svnadmin: E160040:.*"
+  wrong_lock_token = "opaquelocktoken:12345670-9ab8-defc-9ab8-def01234567c"
+  svntest.actions.run_and_verify_svnadmin(None, None,
+                                          expected_error, "unlock", 
+                                          sbox.repo_dir,
+                                          "A/D/G/rho", "jrandom",
+                                          wrong_lock_token)
+  
+  # Test unlocking a patch with the wrong token.
+  expected_output = "'A/D/G/rho' unlocked."
+  svntest.actions.run_and_verify_svnadmin(None, expected_output,
+                                          None, "unlock",
+                                          sbox.repo_dir,
+                                          "A/D/G/rho", "jrandom",
+                                          lock_token)
+
+  # Install lock/unlock prevention hooks.
+  hook_path = svntest.main.get_pre_lock_hook_path(sbox.repo_dir)
+  svntest.main.create_python_hook_script(hook_path, 'import sys; sys.exit(1)')
+  hook_path = svntest.main.get_pre_unlock_hook_path(sbox.repo_dir)
+  svntest.main.create_python_hook_script(hook_path, 'import sys; sys.exit(1)')
+  
   # Test locking path without --bypass-hooks to see that hook script
   # is really getting executed.
   expected_error = ".*svnadmin: E165001:.*"
-  hook_path = svntest.main.get_pre_lock_hook_path(sbox.repo_dir)
-  svntest.main.create_python_hook_script(hook_path, 'import sys; sys.exit(1)')
-
   svntest.actions.run_and_verify_svnadmin(None, None,
                                           expected_error, "lock", 
                                           sbox.repo_dir,
                                           "iota", "jrandom",
                                           comment_path)
 
+  # Fetch the lock token for our remaining locked path.
+  exit_code, output, errput = svntest.main.run_svnadmin("lslocks",
+                                                        sbox.repo_dir,
+                                                        "iota")
+  iota_token = None
+  for line in output:
+    if line.startswith("UUID Token: opaquelocktoken:"):
+      iota_token = line[12:].rstrip()
+      break
+  if iota_token is None:
+    raise svntest.Failure("Unable to lookup lock token for 'iota'")
+
+  # Try to unlock a path with the correct token but with a
+  # preventative hook in place.
+  expected_error = ".*svnadmin: E165001:.*"
+  svntest.actions.run_and_verify_svnadmin(None, None,
+                                          expected_error, "unlock", 
+                                          sbox.repo_dir,
+                                          "iota", "jrandom",
+                                          iota_token)
+
+  # Finally, unlock the path with --bypass-hooks.
+  expected_output = "'iota' unlocked."
+  svntest.actions.run_and_verify_svnadmin(None, expected_output,
+                                          None, "unlock",
+                                          "--bypass-hooks",
+                                          sbox.repo_dir,
+                                          "iota", "jrandom",
+                                          iota_token)
+
+
 ########################################################################
 # Run the tests
 

Modified: subversion/trunk/subversion/tests/cmdline/svntest/main.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svntest/main.py?rev=1228371&r1=1228370&r2=1228371&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svntest/main.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svntest/main.py Fri Jan  6 19:50:30 2012
@@ -324,6 +324,11 @@ def get_pre_lock_hook_path(repo_dir):
 
   return os.path.join(repo_dir, "hooks", "pre-lock")
 
+def get_pre_unlock_hook_path(repo_dir):
+  "Return the path of the pre-unlock hook script in REPO_DIR."
+
+  return os.path.join(repo_dir, "hooks", "pre-unlock")
+
 def get_svnserve_conf_file_path(repo_dir):
   "Return the path of the svnserve.conf file in REPO_DIR."
 



Mime
View raw message