bdb-err.c revision 251881
1285SN/A/* 2462SN/A * err.c : implementation of fs-private error functions 3285SN/A * 4285SN/A * ==================================================================== 5285SN/A * Licensed to the Apache Software Foundation (ASF) under one 6285SN/A * or more contributor license agreements. See the NOTICE file 7285SN/A * distributed with this work for additional information 8285SN/A * regarding copyright ownership. The ASF licenses this file 9285SN/A * to you under the Apache License, Version 2.0 (the 10285SN/A * "License"); you may not use this file except in compliance 11285SN/A * with the License. You may obtain a copy of the License at 12285SN/A * 13285SN/A * http://www.apache.org/licenses/LICENSE-2.0 14285SN/A * 15285SN/A * Unless required by applicable law or agreed to in writing, 16285SN/A * software distributed under the License is distributed on an 17285SN/A * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18285SN/A * KIND, either express or implied. See the License for the 19285SN/A * specific language governing permissions and limitations 20285SN/A * under the License. 21285SN/A * ==================================================================== 22285SN/A */ 23285SN/A 24285SN/A 25285SN/A 26285SN/A#include <stdlib.h> 27285SN/A#include <stdarg.h> 28285SN/A 29285SN/A#include <apr_strings.h> 30285SN/A 31285SN/A#include "svn_fs.h" 32285SN/A#include "../fs.h" 33285SN/A#include "../err.h" 34285SN/A#include "../../libsvn_fs/fs-loader.h" 35285SN/A#include "bdb-err.h" 36285SN/A 37285SN/A#define SVN_WANT_BDB 38285SN/A#include "svn_private_config.h" 39285SN/A 40285SN/A 41285SN/A/* Return a distinguished error for any db error code we want to detect 42285SN/A * programatically; otherwise return a generic error. 43285SN/A */ 44285SN/Astatic int 45285SN/Abdb_err_to_apr_err(int db_err) 46285SN/A{ 47285SN/A if (db_err == DB_LOCK_DEADLOCK) 48285SN/A return SVN_ERR_FS_BERKELEY_DB_DEADLOCK; 49285SN/A else 50285SN/A return SVN_ERR_FS_BERKELEY_DB; 51285SN/A} 52285SN/A 53285SN/A 54285SN/Asvn_error_t * 55285SN/Asvn_fs_bdb__dberr(bdb_env_baton_t *bdb_baton, int db_err) 56285SN/A{ 57285SN/A svn_error_t *child_errors; 58285SN/A 59285SN/A child_errors = bdb_baton->error_info->pending_errors; 60285SN/A bdb_baton->error_info->pending_errors = NULL; 61285SN/A 62285SN/A return svn_error_create(bdb_err_to_apr_err(db_err), child_errors, 63285SN/A db_strerror(db_err)); 64285SN/A} 65285SN/A 66285SN/A 67285SN/Asvn_error_t * 68285SN/Asvn_fs_bdb__dberrf(bdb_env_baton_t *bdb_baton, 69285SN/A int db_err, const char *fmt, ...) 70285SN/A{ 71285SN/A va_list ap; 72285SN/A char *msg; 73285SN/A svn_error_t *err; 74285SN/A svn_error_t *child_errors; 75285SN/A 76285SN/A child_errors = bdb_baton->error_info->pending_errors; 77285SN/A bdb_baton->error_info->pending_errors = NULL; 78285SN/A 79285SN/A err = svn_error_create(bdb_err_to_apr_err(db_err), child_errors, NULL); 80285SN/A 81285SN/A va_start(ap, fmt); 82285SN/A msg = apr_pvsprintf(err->pool, fmt, ap); 83285SN/A va_end(ap); 84285SN/A err->message = apr_psprintf(err->pool, "%s%s", msg, db_strerror(db_err)); 85285SN/A return svn_error_trace(err); 86285SN/A} 87285SN/A 88285SN/A 89285SN/Asvn_error_t * 90svn_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} 107