Author: philip
Date: Wed Dec 16 18:49:57 2009
New Revision: 891376

URL: http://svn.apache.org/viewvc?rev=891376&view=rev
Log:
Ensure that per-directory locks are only taken in the correct directory.

* subversion/libsvn_wc/wc_db.c
  (svn_wc__db_wclock_set): Assert that the lock is for the directory itself.

* subversion/libsvn_wc/lock.c
  (svn_wc__acquire_write_lock): Only try to lock if the directory is a
   working copy.

* subversion/libsvn_client/add.c
  (svn_client_add4): Take lock after adding parents (as was the case in 1.6).
  (add_parent_dirs): Add comment.

* subversion/tests/cmdline/basic_tests.py
  (basic_mkdir_wc_with_parents): Mark as PASS.

Modified:
    subversion/trunk/subversion/libsvn_client/add.c
    subversion/trunk/subversion/libsvn_wc/lock.c
    subversion/trunk/subversion/libsvn_wc/wc_db.c
    subversion/trunk/subversion/tests/cmdline/basic_tests.py

Modified: subversion/trunk/subversion/libsvn_client/add.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/add.c?rev=891376&r1=891375&r2=891376&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/add.c (original)
+++ subversion/trunk/subversion/libsvn_client/add.c Wed Dec 16 18:49:57 2009
@@ -556,6 +556,8 @@
 
   parent_abspath = svn_dirent_dirname(local_abspath, scratch_pool);
 
+  /* ### Do we need locks here?  Are locks being enforced? 1.6 used to
+         acquire and release locks. */
   SVN_ERR(add_parent_dirs(ctx, parent_abspath, scratch_pool));
   SVN_ERR(svn_wc_add4(ctx->wc_ctx, local_abspath, svn_depth_infinity,
                       NULL, SVN_INVALID_REVNUM,
@@ -595,28 +597,18 @@
   else
     parent_abspath = svn_dirent_dirname(local_abspath, pool);
 
-  SVN_ERR(svn_wc__acquire_write_lock(NULL, ctx->wc_ctx, parent_abspath,
-                                     pool, pool));
-
   if (add_parents)
     {
       apr_pool_t *subpool;
 
       subpool = svn_pool_create(pool);
-      err = add_parent_dirs(ctx, parent_abspath, subpool);
-
-      /* We need to be sure we release our working copy locks if we bump
-         into a situation where we couldn't add the parents. */
-      if (err)
-        return svn_error_return(
-                    svn_error_compose_create(
-                      err,
-                      svn_wc__release_write_lock(ctx->wc_ctx, parent_abspath,
-                                                 pool)));
-
+      SVN_ERR(add_parent_dirs(ctx, parent_abspath, subpool));
       svn_pool_destroy(subpool);
     }
 
+  SVN_ERR(svn_wc__acquire_write_lock(NULL, ctx->wc_ctx, parent_abspath,
+                                     pool, pool));
+
   err = add(local_abspath, depth, force, no_ignore, ctx, pool);
 
   /* ### Currently we rely on the fact that this releases all our write locks

Modified: subversion/trunk/subversion/libsvn_wc/lock.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/lock.c?rev=891376&r1=891375&r2=891376&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/lock.c (original)
+++ subversion/trunk/subversion/libsvn_wc/lock.c Wed Dec 16 18:49:57 2009
@@ -1734,12 +1734,12 @@
   apr_pool_t *iterpool;
   const apr_array_header_t *children;
   svn_boolean_t parent_is_anchor = FALSE;
-  int i;
+  int format, i;
+  svn_error_t *err;
 
   if (anchor_abspath)
     {
       const char *parent_abspath, *base;
-      svn_error_t *err;
 
       svn_dirent_split(local_abspath, &parent_abspath, &base, scratch_pool);
       err = svn_wc__db_read_children(&children, wc_ctx->db, parent_abspath,
@@ -1791,8 +1791,15 @@
                                            NULL, iterpool));
     }
 
-  SVN_ERR(svn_wc__db_wclock_set(wc_ctx->db, local_abspath, 0, iterpool));
-  SVN_ERR(svn_wc__db_temp_mark_locked(wc_ctx->db, local_abspath, iterpool));
+  /* We don't want to try and lock an unversioned directory that
+     obstructs a versioned directory. */
+  err = svn_wc__internal_check_wc(&format, wc_ctx->db, local_abspath, 
iterpool);
+  if (!err && format)
+    {
+      SVN_ERR(svn_wc__db_wclock_set(wc_ctx->db, local_abspath, 0, iterpool));
+      SVN_ERR(svn_wc__db_temp_mark_locked(wc_ctx->db, local_abspath, 
iterpool));
+    }
+  svn_error_clear(err);
 
   svn_pool_destroy(iterpool);
 

Modified: subversion/trunk/subversion/libsvn_wc/wc_db.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db.c?rev=891376&r1=891375&r2=891376&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db.c (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db.c Wed Dec 16 18:49:57 2009
@@ -5583,12 +5583,28 @@
                       int levels_to_lock,
                       apr_pool_t *scratch_pool)
 {
+  svn_wc__db_pdh_t *pdh;
+  const char *local_relpath;
   svn_sqlite__stmt_t *stmt;
   svn_error_t *err;
 
-  SVN_ERR(get_statement_for_path(&stmt, db, local_abspath,
-                                 STMT_INSERT_WC_LOCK, scratch_pool));
-  SVN_ERR(svn_sqlite__bind_int64(stmt, 3, levels_to_lock));
+  SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
+
+  SVN_ERR(parse_local_abspath(&pdh, &local_relpath, db, local_abspath,
+                              svn_sqlite__mode_readwrite,
+                              scratch_pool, scratch_pool));
+  VERIFY_USABLE_PDH(pdh);
+
+  /* ### Can only lock this directory in the per-dir layout.  This is
+     ### a temporary restriction until metadata gets centralised.
+     ### Perhaps this should be a runtime error, rather than an
+     ### assert?  Perhaps check the path is versioned? */
+  SVN_ERR_ASSERT(*local_relpath == '\0');
+
+  SVN_ERR(svn_sqlite__get_statement(&stmt, pdh->wcroot->sdb,
+                                    STMT_INSERT_WC_LOCK));
+  SVN_ERR(svn_sqlite__bindf(stmt, "isi", pdh->wcroot->wc_id, local_relpath,
+                            levels_to_lock));
   err = svn_sqlite__insert(NULL, stmt);
   if (err)
     return svn_error_createf(SVN_ERR_WC_LOCKED, err,

Modified: subversion/trunk/subversion/tests/cmdline/basic_tests.py
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/basic_tests.py?rev=891376&r1=891375&r2=891376&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/basic_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/basic_tests.py Wed Dec 16 
18:49:57 2009
@@ -2491,8 +2491,7 @@
               basic_update,
               basic_mkdir_url,
               basic_mkdir_url_with_parents,
-              Wimp("currently, WC locks are being left behind",
-                   basic_mkdir_wc_with_parents),
+              basic_mkdir_wc_with_parents,
               basic_corruption,
               basic_merging_update,
               basic_conflict,


Reply via email to