You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2013/02/28 18:18:07 UTC

svn commit: r1451258 - in /subversion/trunk/subversion: include/private/svn_wc_private.h libsvn_wc/copy.c libsvn_wc/delete.c

Author: rhuijben
Date: Thu Feb 28 17:18:06 2013
New Revision: 1451258

URL: http://svn.apache.org/r1451258
Log:
Make move error condition handling a bit more secure by hiding
an api and making a few checks occur earlier.

* subversion/include/private/svn_wc_private.h
  (svn_wc__delete_internal): Remove function. Users can just use
    svn_wc_delete4 or svn_wc__move2().

* subversion/libsvn_wc/copy.c
  (svn_wc__move2): Call svn_wc__db_op_delete() directly.

* subversion/libsvn_wc/delete.c
  (copy_or_move): Check for some cases of invalid moves.
  (svn_wc__delete_internal): Rename to...
  (svn_wc_delete4): ... this.
  (svn_wc_delete4): Remove wrapper function.

Modified:
    subversion/trunk/subversion/include/private/svn_wc_private.h
    subversion/trunk/subversion/libsvn_wc/copy.c
    subversion/trunk/subversion/libsvn_wc/delete.c

Modified: subversion/trunk/subversion/include/private/svn_wc_private.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_wc_private.h?rev=1451258&r1=1451257&r2=1451258&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_wc_private.h (original)
+++ subversion/trunk/subversion/include/private/svn_wc_private.h Thu Feb 28 17:18:06 2013
@@ -1193,34 +1193,13 @@ svn_wc__get_info(svn_wc_context_t *wc_ct
                  void *cancel_baton,
                  apr_pool_t *scratch_pool);
 
-/* Internal version of svn_wc_delete4(). It has one additional parameter,
- * MOVED_TO_ABSPATH. If not NULL, this parameter indicates that the
- * delete operation is the delete-half of a move.
- *
- * ### Inconsistency: if DELETE_UNVERSIONED_TARGET is FALSE and a target is
- *     unversioned, svn_wc__delete_many() will continue whereas
- *     svn_wc__delete_internal() will throw an error.
- */
-svn_error_t *
-svn_wc__delete_internal(svn_wc_context_t *wc_ctx,
-                        const char *local_abspath,
-                        svn_boolean_t keep_local,
-                        svn_boolean_t delete_unversioned_target,
-                        const char *moved_to_abspath,
-                        svn_cancel_func_t cancel_func,
-                        void *cancel_baton,
-                        svn_wc_notify_func2_t notify_func,
-                        void *notify_baton,
-                        apr_pool_t *scratch_pool);
-
-
 /* Alternative version of svn_wc_delete4().
  * It can delete multiple TARGETS more efficiently (within a single sqlite
  * transaction per working copy), but lacks support for moves.
  *
  * ### Inconsistency: if DELETE_UNVERSIONED_TARGET is FALSE and a target is
  *     unversioned, svn_wc__delete_many() will continue whereas
- *     svn_wc__delete_internal() will throw an error.
+ *     svn_wc_delete4() will throw an error.
  */
 svn_error_t *
 svn_wc__delete_many(svn_wc_context_t *wc_ctx,

Modified: subversion/trunk/subversion/libsvn_wc/copy.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/copy.c?rev=1451258&r1=1451257&r2=1451258&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/copy.c (original)
+++ subversion/trunk/subversion/libsvn_wc/copy.c Thu Feb 28 17:18:06 2013
@@ -545,12 +545,14 @@ copy_or_move(svn_boolean_t *move_degrade
     svn_wc__db_status_t dstdir_status;
     const char *src_repos_root_url, *dst_repos_root_url;
     const char *src_repos_uuid, *dst_repos_uuid;
+    const char *src_repos_relpath;
 
-    err = svn_wc__db_read_info(&src_status, &src_db_kind, NULL, NULL,
-                               &src_repos_root_url, &src_repos_uuid, NULL,
-                               NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-                               NULL, NULL, NULL, NULL, NULL, NULL, &conflicted,
-                               NULL, NULL, NULL, NULL, NULL, NULL,
+    err = svn_wc__db_read_info(&src_status, &src_db_kind, NULL,
+                               &src_repos_relpath, &src_repos_root_url,
+                               &src_repos_uuid, NULL, NULL, NULL, NULL, NULL,
+                               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+                               NULL, &conflicted, NULL, NULL, NULL, NULL,
+                               NULL, NULL,
                                db, src_abspath, scratch_pool, scratch_pool);
 
     if (err && err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND)
@@ -588,6 +590,23 @@ copy_or_move(svn_boolean_t *move_degrade
           break;
       }
 
+     if (is_move && ! strcmp(src_abspath, src_wcroot_abspath))
+      {
+        return svn_error_createf(SVN_ERR_WC_PATH_UNEXPECTED_STATUS, NULL,
+                                 _("'%s' is the root of a working copy and "
+                                   "cannot be moved"),
+                                   svn_dirent_local_style(src_abspath,
+                                                          scratch_pool));
+      }
+    if (is_move && src_repos_relpath && !src_repos_relpath[0])
+      {
+        return svn_error_createf(SVN_ERR_WC_PATH_UNEXPECTED_STATUS, NULL,
+                                 _("'%s' represents the repository root "
+                                   "and cannot be moved"),
+                                 svn_dirent_local_style(src_abspath,
+                                                        scratch_pool));
+      }
+
     err = svn_wc__db_read_info(&dstdir_status, NULL, NULL, NULL,
                                &dst_repos_root_url, &dst_repos_uuid, NULL,
                                NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -1017,11 +1036,13 @@ svn_wc__move2(svn_wc_context_t *wc_ctx,
     SVN_ERR(remove_node_conflict_markers(db, src_abspath, dst_abspath,
                                          scratch_pool));
 
-  SVN_ERR(svn_wc__delete_internal(wc_ctx, src_abspath, TRUE, FALSE,
-                                  move_degraded_to_copy ? NULL : dst_abspath,
-                                  cancel_func, cancel_baton,
-                                  notify_func, notify_baton,
-                                  scratch_pool));
+  SVN_ERR(svn_wc__db_op_delete(db, src_abspath,
+                               move_degraded_to_copy ? NULL : dst_abspath,
+                               TRUE /* delete_dir_externals */,
+                               NULL /* conflict */, NULL /* work_items */,
+                               cancel_func, cancel_baton,
+                               notify_func, notify_baton,
+                               scratch_pool));
 
   return SVN_NO_ERROR;
 }

Modified: subversion/trunk/subversion/libsvn_wc/delete.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/delete.c?rev=1451258&r1=1451257&r2=1451258&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/delete.c (original)
+++ subversion/trunk/subversion/libsvn_wc/delete.c Thu Feb 28 17:18:06 2013
@@ -309,16 +309,15 @@ svn_wc__delete_many(svn_wc_context_t *wc
 }
 
 svn_error_t *
-svn_wc__delete_internal(svn_wc_context_t *wc_ctx,
-                        const char *local_abspath,
-                        svn_boolean_t keep_local,
-                        svn_boolean_t delete_unversioned_target,
-                        const char *moved_to_abspath,
-                        svn_cancel_func_t cancel_func,
-                        void *cancel_baton,
-                        svn_wc_notify_func2_t notify_func,
-                        void *notify_baton,
-                        apr_pool_t *scratch_pool)
+svn_wc_delete4(svn_wc_context_t *wc_ctx,
+               const char *local_abspath,
+               svn_boolean_t keep_local,
+               svn_boolean_t delete_unversioned_target,
+               svn_cancel_func_t cancel_func,
+               void *cancel_baton,
+               svn_wc_notify_func2_t notify_func,
+               void *notify_baton,
+               apr_pool_t *scratch_pool)
 {
   apr_pool_t *pool = scratch_pool;
   svn_wc__db_t *db = wc_ctx->db;
@@ -394,7 +393,8 @@ svn_wc__delete_internal(svn_wc_context_t
                                          scratch_pool, scratch_pool));
         }
 
-  SVN_ERR(svn_wc__db_op_delete(db, local_abspath, moved_to_abspath,
+  SVN_ERR(svn_wc__db_op_delete(db, local_abspath,
+                               NULL /*moved_to_abspath */,
                                !keep_local /* delete_dir_externals */,
                                NULL, work_items,
                                cancel_func, cancel_baton,
@@ -409,26 +409,6 @@ svn_wc__delete_internal(svn_wc_context_t
 }
 
 svn_error_t *
-svn_wc_delete4(svn_wc_context_t *wc_ctx,
-               const char *local_abspath,
-               svn_boolean_t keep_local,
-               svn_boolean_t delete_unversioned_target,
-               svn_cancel_func_t cancel_func,
-               void *cancel_baton,
-               svn_wc_notify_func2_t notify_func,
-               void *notify_baton,
-               apr_pool_t *scratch_pool)
-{
-  return svn_error_trace(svn_wc__delete_internal(wc_ctx, local_abspath,
-                                                 keep_local,
-                                                 delete_unversioned_target,
-                                                 NULL,
-                                                 cancel_func, cancel_baton,
-                                                 notify_func, notify_baton,
-                                                 scratch_pool));
-}
-
-svn_error_t *
 svn_wc__internal_remove_from_revision_control(svn_wc__db_t *db,
                                               const char *local_abspath,
                                               svn_boolean_t destroy_wf,