1 /* miscellaneous-table.c : operations on the `miscellaneous' table
3 * ====================================================================
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
20 * ====================================================================
25 #include "bdb_compat.h"
27 #include "svn_pools.h"
32 #include "../../libsvn_fs/fs-loader.h"
34 #include "miscellaneous-table.h"
36 #include "private/svn_fs_util.h"
40 svn_fs_bdb__open_miscellaneous_table(DB **miscellaneous_p,
44 const u_int32_t open_flags = (create ? (DB_CREATE | DB_EXCL) : 0);
48 BDB_ERR(svn_fs_bdb__check_version());
49 BDB_ERR(db_create(&miscellaneous, env, 0));
50 error = (miscellaneous->open)(SVN_BDB_OPEN_PARAMS(miscellaneous, NULL),
51 "miscellaneous", 0, DB_BTREE,
54 /* Create the table if it doesn't yet exist. This is a form of
55 automagical repository upgrading. */
56 if (error == ENOENT && (! create))
58 BDB_ERR(miscellaneous->close(miscellaneous, 0));
59 return svn_fs_bdb__open_miscellaneous_table(miscellaneous_p, env, TRUE);
63 /* If we're creating the table from scratch (not upgrading), record the
69 BDB_ERR(miscellaneous->put
71 svn_fs_base__str_to_dbt
72 (&key, SVN_FS_BASE__MISC_FORWARD_DELTA_UPGRADE),
73 svn_fs_base__str_to_dbt(&value, "0"), 0));
76 *miscellaneous_p = miscellaneous;
82 svn_fs_bdb__miscellaneous_set(svn_fs_t *fs,
88 base_fs_data_t *bfd = fs->fsap_data;
91 svn_fs_base__str_to_dbt(&key, key_str);
94 svn_fs_base__trail_debug(trail, "miscellaneous", "del");
95 return BDB_WRAP(fs, N_("deleting record from 'miscellaneous' table"),
96 bfd->miscellaneous->del(bfd->miscellaneous,
97 trail->db_txn, &key, 0));
101 svn_fs_base__str_to_dbt(&value, val);
102 svn_fs_base__trail_debug(trail, "miscellaneous", "add");
103 return BDB_WRAP(fs, N_("storing miscellaneous record"),
104 bfd->miscellaneous->put(bfd->miscellaneous,
112 svn_fs_bdb__miscellaneous_get(const char **val,
118 base_fs_data_t *bfd = fs->fsap_data;
123 svn_fs_base__trail_debug(trail, "miscellaneous", "get");
124 db_err = bfd->miscellaneous->get(bfd->miscellaneous, trail->db_txn,
125 svn_fs_base__str_to_dbt(&key, key_str),
126 svn_fs_base__result_dbt(&value), 0);
127 svn_fs_base__track_dbt(&value, pool);
129 if (db_err != DB_NOTFOUND)
131 SVN_ERR(BDB_WRAP(fs, N_("fetching miscellaneous record"), db_err));
132 *val = apr_pstrmemdup(pool, value.data, value.size);