1 /* uuids-table.c : operations on the `uuids' 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"
31 #include "../../libsvn_fs/fs-loader.h"
33 #include "uuids-table.h"
35 #include "svn_private_config.h"
38 /*** Creating and opening the uuids table.
39 When the table is created, the repository's uuid is
40 generated and stored as record #1. ***/
43 svn_fs_bdb__open_uuids_table(DB **uuids_p,
47 const u_int32_t open_flags = (create ? (DB_CREATE | DB_EXCL) : 0);
51 BDB_ERR(svn_fs_bdb__check_version());
52 BDB_ERR(db_create(&uuids, env, 0));
53 BDB_ERR(uuids->set_re_len(uuids, APR_UUID_FORMATTED_LENGTH));
55 error = (uuids->open)(SVN_BDB_OPEN_PARAMS(uuids, NULL),
59 /* This is a temporary compatibility check; it creates the
60 UUIDs table if one does not already exist. */
61 if (error == ENOENT && (! create))
63 BDB_ERR(uuids->close(uuids, 0));
64 return svn_fs_bdb__open_uuids_table(uuids_p, env, TRUE);
71 char buffer[APR_UUID_FORMATTED_LENGTH + 1];
76 svn_fs_base__clear_dbt(&key);
78 key.size = sizeof(recno);
80 key.flags |= DB_DBT_USERMEM;
82 svn_fs_base__clear_dbt(&value);
84 value.size = sizeof(buffer) - 1;
87 apr_uuid_format(buffer, &uuid);
89 BDB_ERR(uuids->put(uuids, 0, &key, &value, DB_APPEND));
96 svn_error_t *svn_fs_bdb__get_uuid(svn_fs_t *fs,
102 base_fs_data_t *bfd = fs->fsap_data;
103 char buffer[APR_UUID_FORMATTED_LENGTH + 1];
104 DB *uuids = bfd->uuids;
108 svn_fs_base__clear_dbt(&key);
110 key.size = sizeof(idx);
112 svn_fs_base__clear_dbt(&value);
114 value.size = sizeof(buffer) - 1;
115 value.ulen = value.size;
116 value.flags |= DB_DBT_USERMEM;
118 svn_fs_base__trail_debug(trail, "uuids", "get");
119 SVN_ERR(BDB_WRAP(fs, N_("get repository uuid"),
120 uuids->get(uuids, trail->db_txn, &key, &value, 0)));
122 *uuid = apr_pstrmemdup(pool, value.data, value.size);
127 svn_error_t *svn_fs_bdb__set_uuid(svn_fs_t *fs,
133 base_fs_data_t *bfd = fs->fsap_data;
134 DB *uuids = bfd->uuids;
138 svn_fs_base__clear_dbt(&key);
140 key.size = sizeof(idx);
142 svn_fs_base__clear_dbt(&value);
143 value.size = (u_int32_t) strlen(uuid);
144 value.data = apr_pstrmemdup(pool, uuid, value.size + 1);
146 svn_fs_base__trail_debug(trail, "uuids", "put");
147 return BDB_WRAP(fs, N_("set repository uuid"),
148 uuids->put(uuids, trail->db_txn, &key, &value, 0));