]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/subversion/subversion/libsvn_fs_base/bdb/bdb-err.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / subversion / subversion / libsvn_fs_base / bdb / bdb-err.c
1 /*
2  * err.c : implementation of fs-private error functions
3  *
4  * ====================================================================
5  *    Licensed to the Apache Software Foundation (ASF) under one
6  *    or more contributor license agreements.  See the NOTICE file
7  *    distributed with this work for additional information
8  *    regarding copyright ownership.  The ASF licenses this file
9  *    to you under the Apache License, Version 2.0 (the
10  *    "License"); you may not use this file except in compliance
11  *    with the License.  You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  *    Unless required by applicable law or agreed to in writing,
16  *    software distributed under the License is distributed on an
17  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  *    KIND, either express or implied.  See the License for the
19  *    specific language governing permissions and limitations
20  *    under the License.
21  * ====================================================================
22  */
23
24
25 \f
26 #include <stdlib.h>
27 #include <stdarg.h>
28
29 #include <apr_strings.h>
30
31 #include "svn_fs.h"
32 #include "../fs.h"
33 #include "../err.h"
34 #include "../../libsvn_fs/fs-loader.h"
35 #include "bdb-err.h"
36
37 #define SVN_WANT_BDB
38 #include "svn_private_config.h"
39
40 \f
41 /* Return a distinguished error for any db error code we want to detect
42  * programatically; otherwise return a generic error.
43  */
44 static int
45 bdb_err_to_apr_err(int db_err)
46 {
47   if (db_err == DB_LOCK_DEADLOCK)
48     return SVN_ERR_FS_BERKELEY_DB_DEADLOCK;
49   else
50     return SVN_ERR_FS_BERKELEY_DB;
51 }
52
53 \f
54 svn_error_t *
55 svn_fs_bdb__dberr(bdb_env_baton_t *bdb_baton, int db_err)
56 {
57   svn_error_t *child_errors;
58
59   child_errors = bdb_baton->error_info->pending_errors;
60   bdb_baton->error_info->pending_errors = NULL;
61
62   return svn_error_create(bdb_err_to_apr_err(db_err), child_errors,
63                           db_strerror(db_err));
64 }
65
66 \f
67 svn_error_t *
68 svn_fs_bdb__dberrf(bdb_env_baton_t *bdb_baton,
69                    int db_err, const char *fmt, ...)
70 {
71   va_list ap;
72   char *msg;
73   svn_error_t *err;
74   svn_error_t *child_errors;
75
76   child_errors = bdb_baton->error_info->pending_errors;
77   bdb_baton->error_info->pending_errors = NULL;
78
79   err = svn_error_create(bdb_err_to_apr_err(db_err), child_errors, NULL);
80
81   va_start(ap, fmt);
82   msg = apr_pvsprintf(err->pool, fmt, ap);
83   va_end(ap);
84   err->message = apr_psprintf(err->pool, "%s%s", msg, db_strerror(db_err));
85   return svn_error_trace(err);
86 }
87
88 \f
89 svn_error_t *
90 svn_fs_bdb__wrap_db(svn_fs_t *fs, const char *operation, int db_err)
91 {
92   base_fs_data_t *bfd = fs->fsap_data;
93
94   if (! db_err)
95     {
96       svn_error_clear(bfd->bdb->error_info->pending_errors);
97       bfd->bdb->error_info->pending_errors = NULL;
98       return SVN_NO_ERROR;
99     }
100
101   bfd = fs->fsap_data;
102   return svn_fs_bdb__dberrf
103     (bfd->bdb, db_err,
104      _("Berkeley DB error for filesystem '%s' while %s:\n"),
105      fs->path ? fs->path : "(none)", _(operation));
106 }