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/12/27 18:18:36 UTC

svn commit: r1553697 - in /subversion/trunk/subversion/libsvn_ra_serf: commit.c get_lock.c getlocks.c merge.c ra_serf.h update.c util.c

Author: rhuijben
Date: Fri Dec 27 17:18:35 2013
New Revision: 1553697

URL: http://svn.apache.org/r1553697
Log:
Make more cases of http status processing in libsvn_ra_serf use the standard
errors reporting.

* subversion/libsvn_ra_serf/commit.c
  (unexpected_status_error): Move function to util.c and rename.
  (checkout_node): Update caller.
  (proppatch_walker): Add error case to avoid compiler warning.
  (proppatch_resource,
   open_root,
   delete_entry,
   add_directory,
   add_file,
   close_file,
   close_edit
   abort_edit): Update caller.

* subversion/libsvn_ra_serf/getlocks.c
  (svn_ra_serf__get_locks): Explicitly handle results.

* subversion/libsvn_ra_serf/get_lock.c
  (svn_ra_serf__get_lock): Explicitly handle results.

* subversion/libsvn_ra_serf/merge.c
  (svn_ra_serf__run_merge): Verify result locally instead of making the
    single caller do that.

* subversion/libsvn_ra_serf/ra_serf.h
  (svn_ra_serf__run_merge): Remove output argument.
  (svn_ra_serf__error_on_status): Extend documentation.
  (svn_ra_serf__unexpected_status): New function.

* subversion/libsvn_ra_serf/update.c
  (handle_fetch): Use standard unexpected result handling.
  (finish_report): Eagerly handle http status.

* subversion/libsvn_ra_serf/util.c
  (svn_ra_serf__error_on_status): Tweak message.
  (svn_ra_serf__unexpected_status): New function; mostly copied from commits.c.

Modified:
    subversion/trunk/subversion/libsvn_ra_serf/commit.c
    subversion/trunk/subversion/libsvn_ra_serf/get_lock.c
    subversion/trunk/subversion/libsvn_ra_serf/getlocks.c
    subversion/trunk/subversion/libsvn_ra_serf/merge.c
    subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h
    subversion/trunk/subversion/libsvn_ra_serf/update.c
    subversion/trunk/subversion/libsvn_ra_serf/util.c

Modified: subversion/trunk/subversion/libsvn_ra_serf/commit.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/commit.c?rev=1553697&r1=1553696&r2=1553697&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/commit.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/commit.c Fri Dec 27 17:18:35 2013
@@ -198,30 +198,6 @@ typedef struct file_context_t {
 
 /* Setup routines and handlers for various requests we'll invoke. */
 
-static svn_error_t *
-unexpected_status_error(svn_ra_serf__handler_t *handler)
-{
-  svn_error_t *err;
-
-  err = svn_ra_serf__error_on_status(handler->sline,
-                                     handler->path,
-                                     handler->location);
-
-  if (err)
-    return err;
-
-  if (handler->sline.code == 204)
-    return svn_error_createf(SVN_ERR_FS_ALREADY_EXISTS, NULL,
-                             _("Path '%s' already exists"),
-                             handler->path);
-
-  return svn_error_createf(SVN_ERR_RA_DAV_REQUEST_FAILED, NULL,
-                           _("Unexpected HTTP status %d '%s' on '%s' "
-                             "request to '%s'"),
-                           handler->sline.code, handler->sline.reason,
-                           handler->method, handler->path);
-}
-
 /* Implements svn_ra_serf__request_body_delegate_t */
 static svn_error_t *
 create_checkout_body(serf_bucket_t **bkt,
@@ -307,7 +283,7 @@ checkout_node(const char **working_url,
   SVN_ERR(svn_ra_serf__context_run_one(&handler, scratch_pool));
 
   if (handler.sline.code != 201)
-    return svn_error_trace(unexpected_status_error(&handler));
+    return svn_error_trace(svn_ra_serf__unexpected_status(&handler));
 
   if (handler.location == NULL)
     return svn_error_create(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
@@ -704,6 +680,8 @@ proppatch_walker(void *baton,
     prop_name = apr_pstrcat(wb->body_pool, "S:", name, SVN_VA_NULL);
   else if (strcmp(ns, SVN_DAV_PROP_NS_CUSTOM) == 0)
     prop_name = apr_pstrcat(wb->body_pool, "C:", name, SVN_VA_NULL);
+  else
+    SVN_ERR_MALFUNCTION();
 
   if (cdata_bkt)
     svn_ra_serf__add_open_tag_buckets(body_bkt, alloc, prop_name,
@@ -938,7 +916,7 @@ proppatch_resource(svn_ra_serf__session_
   err = svn_ra_serf__context_run_one(handler, pool);
 
   if (!err && handler->sline.code != 207)
-    err = svn_error_trace(unexpected_status_error(handler));
+    err = svn_error_trace(svn_ra_serf__unexpected_status(handler));
 
   /* Use specific error code for property handling errors.
      Use loop to provide the right result with tracing */
@@ -1360,7 +1338,7 @@ open_root(void *edit_baton,
       SVN_ERR(svn_ra_serf__context_run_one(handler, scratch_pool));
 
       if (handler->sline.code != 201)
-        return svn_error_trace(unexpected_status_error(handler));
+        return svn_error_trace(svn_ra_serf__unexpected_status(handler));
 
       if (! (commit_ctx->txn_root_url && commit_ctx->txn_url))
         {
@@ -1436,7 +1414,7 @@ open_root(void *edit_baton,
       SVN_ERR(svn_ra_serf__context_run_one(handler, scratch_pool));
 
       if (handler->sline.code != 201)
-        return svn_error_trace(unexpected_status_error(handler));
+        return svn_error_trace(svn_ra_serf__unexpected_status(handler));
 
       /* Now go fetch our VCC and baseline so we can do a CHECKOUT. */
       SVN_ERR(svn_ra_serf__discover_vcc(&(commit_ctx->vcc_url),
@@ -1565,7 +1543,7 @@ delete_entry(const char *path,
 
   /* 204 No Content: item successfully deleted */
   if (handler->sline.code != 204)
-    return svn_error_trace(unexpected_status_error(handler));
+    return svn_error_trace(svn_ra_serf__unexpected_status(handler));
 
   svn_hash_sets(dir->commit_ctx->deleted_entries,
                 apr_pstrdup(dir->commit_ctx->pool, path), (void *)1);
@@ -1664,7 +1642,7 @@ add_directory(const char *path,
   SVN_ERR(svn_ra_serf__context_run_one(handler, dir->pool));
 
   if (handler->sline.code != 201)
-    return svn_error_trace(unexpected_status_error(handler));
+    return svn_error_trace(svn_ra_serf__unexpected_status(handler));
 
   *child_baton = dir;
 
@@ -1898,7 +1876,7 @@ add_file(const char *path,
       SVN_ERR(svn_ra_serf__context_run_one(handler, scratch_pool));
 
       if (handler->sline.code != 201)
-        return svn_error_trace(unexpected_status_error(handler));
+        return svn_error_trace(svn_ra_serf__unexpected_status(handler));
     }
   else if (! ((dir->added && !dir->copy_path) ||
            (deleted_parent && deleted_parent[0] != '\0')))
@@ -2123,7 +2101,7 @@ close_file(void *file_baton,
         expected_result = 204; /* Updated */
 
       if (handler->sline.code != expected_result)
-        return svn_error_trace(unexpected_status_error(handler));
+        return svn_error_trace(svn_ra_serf__unexpected_status(handler));
     }
 
   if (ctx->svndiff)
@@ -2160,10 +2138,9 @@ close_edit(void *edit_baton,
   const char *merge_target =
     ctx->activity_url ? ctx->activity_url : ctx->txn_url;
   const svn_commit_info_t *commit_info;
-  int response_code;
 
   /* MERGE our activity */
-  SVN_ERR(svn_ra_serf__run_merge(&commit_info, &response_code,
+  SVN_ERR(svn_ra_serf__run_merge(&commit_info,
                                  ctx->session,
                                  ctx->session->conns[0],
                                  merge_target,
@@ -2171,14 +2148,6 @@ close_edit(void *edit_baton,
                                  ctx->keep_locks,
                                  pool, pool));
 
-  if (response_code != 200)
-    {
-      return svn_error_createf(SVN_ERR_RA_DAV_REQUEST_FAILED, NULL,
-                               _("MERGE request failed: returned %d "
-                                 "(during commit)"),
-                               response_code);
-    }
-
   /* Inform the WC that we did a commit.  */
   if (ctx->callback)
     SVN_ERR(ctx->callback(commit_info, ctx->callback_baton, pool));
@@ -2247,7 +2216,7 @@ abort_edit(void *edit_baton,
       && handler->sline.code != 403
       && handler->sline.code != 404)
     {
-      return svn_error_trace(unexpected_status_error(handler));
+      return svn_error_trace(svn_ra_serf__unexpected_status(handler));
     }
 
   return SVN_NO_ERROR;

Modified: subversion/trunk/subversion/libsvn_ra_serf/get_lock.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/get_lock.c?rev=1553697&r1=1553696&r2=1553697&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/get_lock.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/get_lock.c Fri Dec 27 17:18:35 2013
@@ -301,20 +301,15 @@ svn_ra_serf__get_lock(svn_ra_session_t *
 
   err = svn_ra_serf__context_run_one(handler, pool);
 
-  if (!err)
-    {
-      err = svn_ra_serf__error_on_status(handler->sline,
-                                         handler->path,
-                                         handler->location);
-    }
-
-  if (err)
-    {
-      /* TODO Shh.  We're telling a white lie for now. */
-      return svn_error_trace(
+  if ((err && (handler->sline.code == 500 || handler->sline.code == 501))
+      || svn_error_find_cause(err, SVN_ERR_UNSUPPORTED_FEATURE))
+    return svn_error_trace(
              svn_error_create(SVN_ERR_RA_NOT_IMPLEMENTED, err,
                               _("Server does not support locking features")));
-    }
+  else if (err)
+    return svn_error_trace(err);
+  else if (handler->sline.code != 207)
+    return svn_error_trace(svn_ra_serf__unexpected_status(handler));
 
   *lock = lock_ctx->lock;
 

Modified: subversion/trunk/subversion/libsvn_ra_serf/getlocks.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/getlocks.c?rev=1553697&r1=1553696&r2=1553697&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/getlocks.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/getlocks.c Fri Dec 27 17:18:35 2013
@@ -265,11 +265,16 @@ svn_ra_serf__get_locks(svn_ra_session_t 
 
   /* We get a 404 when a path doesn't exist in HEAD, but it might
      have existed earlier (E.g. 'svn ls http://s/svn/trunk/file@1' */
-  if (handler->sline.code != 404)
+  if (handler->sline.code != 200
+      && handler->sline.code != 404)
     {
-      SVN_ERR(svn_ra_serf__error_on_status(handler->sline,
-                                           handler->path,
-                                           handler->location));
+      svn_error_t *err = svn_ra_serf__unexpected_status(handler);
+
+      if (handler->sline.code == 500 || handler->sline.code == 501)
+        return svn_error_create(SVN_ERR_RA_NOT_IMPLEMENTED, err,
+                                _("Server does not support locking features"));
+
+      return svn_error_trace(err);
     }
 
   *locks = lock_ctx->hash;

Modified: subversion/trunk/subversion/libsvn_ra_serf/merge.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/merge.c?rev=1553697&r1=1553696&r2=1553697&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/merge.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/merge.c Fri Dec 27 17:18:35 2013
@@ -376,7 +376,6 @@ create_merge_body(serf_bucket_t **bkt,
 
 svn_error_t *
 svn_ra_serf__run_merge(const svn_commit_info_t **commit_info,
-                       int *response_code,
                        svn_ra_serf__session_t *session,
                        svn_ra_serf__connection_t *conn,
                        const char *merge_resource_url,
@@ -423,8 +422,10 @@ svn_ra_serf__run_merge(const svn_commit_
 
   SVN_ERR(svn_ra_serf__context_run_one(handler, scratch_pool));
 
+  if (handler->sline.code != 200)
+    return svn_error_trace(svn_ra_serf__unexpected_status(handler));
+
   *commit_info = merge_ctx->commit_info;
-  *response_code = handler->sline.code;
 
   return SVN_NO_ERROR;
 }

Modified: subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h?rev=1553697&r1=1553696&r2=1553697&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h Fri Dec 27 17:18:35 2013
@@ -1364,7 +1364,6 @@ svn_ra_serf__merge_lock_token_list(apr_h
    locks set on the paths included in this commit.  */
 svn_error_t *
 svn_ra_serf__run_merge(const svn_commit_info_t **commit_info,
-                       int *response_code,
                        svn_ra_serf__session_t *session,
                        svn_ra_serf__connection_t *conn,
                        const char *merge_resource_url,
@@ -1807,12 +1806,23 @@ svn_ra_serf__credentials_callback(char *
  * Convert an HTTP STATUS_CODE resulting from a WebDAV request against
  * PATH to the relevant error code.  Use the response-supplied LOCATION
  * where it necessary.
+ *
+ * Returns SVN_NO_ERROR if sline doesn't specify an error condition
  */
 svn_error_t *
 svn_ra_serf__error_on_status(serf_status_line sline,
                              const char *path,
                              const char *location);
 
+/**
+ * Convert an unexpected HTTP STATUS_CODE from a request to the relevant error
+ * code. Unlike svn_ra_serf__error_on_status() this function creates an error
+ * for any result
+ */
+svn_error_t *
+svn_ra_serf__unexpected_status(svn_ra_serf__handler_t *handler);
+
+
 /* ###? */
 svn_error_t *
 svn_ra_serf__copy_into_spillbuf(svn_spillbuf_t **spillbuf,

Modified: subversion/trunk/subversion/libsvn_ra_serf/update.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/update.c?rev=1553697&r1=1553696&r2=1553697&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/update.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/update.c Fri Dec 27 17:18:35 2013
@@ -1128,10 +1128,7 @@ handle_fetch(serf_request_t *request,
      data as its probably an error message. Just bail out instead. */
   if (fetch_ctx->handler->sline.code != 200)
     {
-      err = svn_error_createf(SVN_ERR_RA_DAV_REQUEST_FAILED, NULL,
-                              _("GET request failed: %d %s"),
-                              fetch_ctx->handler->sline.code,
-                              fetch_ctx->handler->sline.reason);
+      err = svn_error_trace(svn_ra_serf__unexpected_status(fetch_ctx->handler));
       return error_fetch(request, fetch_ctx, err);
     }
 
@@ -2970,13 +2967,11 @@ finish_report(void *report_baton,
 
       SVN_ERR(err);
 
+      if (handler->sline.code && handler->sline.code != 200)
+        return svn_error_trace(svn_ra_serf__unexpected_status(handler));
+
       if (status)
         {
-          if (handler->sline.code != 200)
-            SVN_ERR(svn_ra_serf__error_on_status(handler->sline,
-                                                 handler->path,
-                                                 handler->location));
-
           return svn_ra_serf__wrap_err(status, _("Error retrieving REPORT"));
         }
 

Modified: subversion/trunk/subversion/libsvn_ra_serf/util.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/util.c?rev=1553697&r1=1553696&r2=1553697&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/util.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/util.c Fri Dec 27 17:18:35 2013
@@ -1755,12 +1755,15 @@ handle_response(serf_request_t *request,
       serf_bucket_t *hdrs;
       const char *val;
 
+      SVN_DBG(("Found error %d on %s\n", handler->sline.code, handler->path));
+
       hdrs = serf_bucket_response_get_headers(response);
       val = serf_bucket_headers_get(hdrs, "Content-Type");
       if (val && strncasecmp(val, "text/xml", sizeof("text/xml") - 1) == 0)
         {
           svn_ra_serf__server_error_t *server_err;
 
+          SVN_DBG(("Got xml response"));
           SVN_ERR(svn_ra_serf__setup_error_parsing(&server_err, handler,
                                                    FALSE,
                                                    handler->handler_pool,
@@ -1770,6 +1773,7 @@ handle_response(serf_request_t *request,
         }
       else
         {
+            SVN_DBG(("Got no xml response"));
           handler->discard_body = TRUE;
         }
     }
@@ -2193,7 +2197,7 @@ svn_ra_serf__error_on_status(serf_status
                                  _("'%s' is out of date"), path);
       case 409:
         return svn_error_createf(SVN_ERR_FS_CONFLICT, NULL,
-                                 _("'%s' is out of date"), path);
+                                 _("'%s' conflicts"), path);
       case 412:
         return svn_error_createf(SVN_ERR_RA_DAV_PRECONDITION_FAILED, NULL,
                                  _("Precondition on '%s' failed"), path);
@@ -2226,6 +2230,34 @@ svn_ra_serf__error_on_status(serf_status
 }
 
 svn_error_t *
+svn_ra_serf__unexpected_status(svn_ra_serf__handler_t *handler)
+{
+  /* Is it a standard error status? */
+  SVN_ERR(svn_ra_serf__error_on_status(handler->sline,
+                                       handler->path,
+                                       handler->location));
+
+  switch (handler->sline.code)
+    {
+      case 201:
+        return svn_error_createf(SVN_ERR_RA_DAV_REQUEST_FAILED,
+                                 _("Path '%s' unexpectedly created"),
+                                 handler->path);
+      case 204:
+        return svn_error_createf(SVN_ERR_FS_ALREADY_EXISTS, NULL,
+                                 _("Path '%s' already exists"),
+                                 handler->path);
+
+      default:
+        return svn_error_createf(SVN_ERR_RA_DAV_REQUEST_FAILED, NULL,
+                                 _("Unexpected HTTP status %d '%s' on '%s' "
+                                   "request to '%s'"),
+                                 handler->sline.code, handler->sline.reason,
+                                 handler->method, handler->path);
+    }
+}
+
+svn_error_t *
 svn_ra_serf__register_editor_shim_callbacks(svn_ra_session_t *ra_session,
                                     svn_delta_shim_callbacks_t *callbacks)
 {