You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2016/11/18 13:44:30 UTC

svn commit: r1770381 - in /subversion/branches/authzperf/subversion/libsvn_repos: config_file.c config_pool.c

Author: stefan2
Date: Fri Nov 18 13:44:30 2016
New Revision: 1770381

URL: http://svn.apache.org/viewvc?rev=1770381&view=rev
Log:
On the authzperf branch:  Refine error handling.

* subversion/libsvn_repos/config_file.c
  (handle_missing_file): New utility function for unified "not a file"
                         handling.
  (get_repos_config): Use the new helper to return the same error message
                      on missing in-repo config files as currently on /trunk.
  (get_file_config): Add support for the same error handling as for in-repos
                     config files.

* subversion/libsvn_repos/config_pool.c
  (svn_repos__config_pool_get): Provide the file path/url with the error
                                message as we do in other places that
                                parse a config stream.

Modified:
    subversion/branches/authzperf/subversion/libsvn_repos/config_file.c
    subversion/branches/authzperf/subversion/libsvn_repos/config_pool.c

Modified: subversion/branches/authzperf/subversion/libsvn_repos/config_file.c
URL: http://svn.apache.org/viewvc/subversion/branches/authzperf/subversion/libsvn_repos/config_file.c?rev=1770381&r1=1770380&r2=1770381&view=diff
==============================================================================
--- subversion/branches/authzperf/subversion/libsvn_repos/config_file.c (original)
+++ subversion/branches/authzperf/subversion/libsvn_repos/config_file.c Fri Nov 18 13:44:30 2016
@@ -164,6 +164,35 @@ representation_stream(svn_fs_root_t *roo
   return stream;
 }
 
+/* Handle the case of a file PATH / url pointing to anything that is either
+ * not a file or does not exist at all.   The case is given by NODE_KIND.
+ *
+ * If MUST_EXIST is not set and the file does not exist at all, return a
+ * default *STREAM and *CHECKSUM allocated in the context of ACCESS, or an
+ * error otherwise.
+ */
+static svn_error_t *
+handle_missing_file(svn_stream_t **stream,
+                    svn_checksum_t **checksum,
+                    config_access_t *access,
+                    const char *path,
+                    svn_boolean_t must_exist,
+                    svn_node_kind_t node_kind)
+{
+  if (node_kind == svn_node_none && !must_exist)
+    {
+      *stream = svn_stream_empty(access->pool);
+      SVN_ERR(svn_checksum(checksum, svn_checksum_md5, "", 0, access->pool));
+    }
+  else if (node_kind != svn_node_file)
+    {
+      return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
+                               "'%s' is not a file", path);
+    }
+
+  return SVN_NO_ERROR;
+}
+
 /* Open the in-repository file at URL, return its content checksum in
  * *CHECKSUM and the content itself through *STREAM.  Allocate those with
  * the lifetime of ACCESS and use SCRATCH_POOL for temporaries.
@@ -222,14 +251,11 @@ get_repos_config(svn_stream_t **stream,
   SVN_ERR(svn_fs_youngest_rev(&youngest_rev, fs, scratch_pool));
   SVN_ERR(svn_fs_revision_root(&root, fs, youngest_rev, access->pool));
 
-  /* Special case: non-existent paths are handled as "empty" contents. */
+  /* Special case: non-existent paths may be handled as "empty" contents. */
   SVN_ERR(svn_fs_check_path(&node_kind, root, fs_path, scratch_pool));
-  if (node_kind == svn_node_none && !must_exist)
-    {
-      *stream = svn_stream_empty(access->pool);
-      SVN_ERR(svn_checksum(checksum, svn_checksum_md5, "", 0, access->pool));
-      return SVN_NO_ERROR;
-    }
+  if (node_kind != svn_node_file)
+    return svn_error_trace(handle_missing_file(stream, checksum, access,
+                                               url, must_exist, node_kind));
 
   /* Fetch checksum and see whether we already have a matching config */
   SVN_ERR(svn_fs_file_checksum(checksum, svn_checksum_md5, root, fs_path,
@@ -248,9 +274,20 @@ static svn_error_t *
 get_file_config(svn_stream_t **stream,
                 svn_checksum_t **checksum,
                 config_access_t *access,
-                const char *path)
+                const char *path,
+                svn_boolean_t must_exist,
+                apr_pool_t *scratch_pool)
 {
   svn_stringbuf_t *contents;
+  svn_node_kind_t node_kind;
+
+  /* Special case: non-existent paths may be handled as "empty" contents. */
+  SVN_ERR(svn_io_check_path(path, &node_kind, scratch_pool));
+  if (node_kind != svn_node_file)
+    return svn_error_trace(handle_missing_file(stream, checksum, access,
+                                               path, must_exist, node_kind));
+
+  /* Now, we should be able to read the file. */
   SVN_ERR(svn_stringbuf_from_file2(&contents, path, access->pool));
 
   /* calculate MD5 over the whole file contents */
@@ -292,7 +329,8 @@ svn_repos__get_config(svn_stream_t **str
     SVN_ERR(get_repos_config(stream, checksum, access, path, must_exist,
                              scratch_pool));
   else
-    SVN_ERR(get_file_config(stream, checksum, access, path));
+    SVN_ERR(get_file_config(stream, checksum, access, path, must_exist,
+                            scratch_pool));
 
   return SVN_NO_ERROR;
 }

Modified: subversion/branches/authzperf/subversion/libsvn_repos/config_pool.c
URL: http://svn.apache.org/viewvc/subversion/branches/authzperf/subversion/libsvn_repos/config_pool.c?rev=1770381&r1=1770380&r2=1770381&view=diff
==============================================================================
--- subversion/branches/authzperf/subversion/libsvn_repos/config_pool.c (original)
+++ subversion/branches/authzperf/subversion/libsvn_repos/config_pool.c Fri Nov 18 13:44:30 2016
@@ -123,7 +123,10 @@ svn_repos__config_pool_get(svn_config_t
   err = svn_repos__get_config(&stream, &checksum, access, path, must_exist,
                               scratch_pool);
   if (!err)
-    err = find_config(cfg, config_pool, stream, checksum, pool, scratch_pool);
+    err = svn_error_quick_wrapf(find_config(cfg, config_pool, stream,
+                                            checksum, pool, scratch_pool),
+                                "Error while parsing config file: '%s':",
+                                path);
 
   svn_error_clear(err);
   if (!*cfg)