1
/* uuids-table.c : operations on the `uuids' table
3
* ====================================================================
4
* Copyright (c) 2000-2004 CollabNet. All rights reserved.
6
* This software is licensed as described in the file COPYING, which
7
* you should have received as part of this distribution. The terms
8
* are also available at http://subversion.tigris.org/license-1.html.
9
* If newer versions of this license are posted there, you may use a
10
* newer version instead, at your option.
12
* This software consists of voluntary contributions made by many
13
* individuals. For exact contribution history, see the revision
14
* history and logs, available at http://subversion.tigris.org/.
15
* ====================================================================
20
#include "bdb_compat.h"
26
#include "../../libsvn_fs/fs-loader.h"
28
#include "uuids-table.h"
30
#include "svn_private_config.h"
33
/*** Creating and opening the uuids table.
34
When the table is created, the repository's uuid is
35
generated and stored as record #1. ***/
38
svn_fs_bdb__open_uuids_table (DB **uuids_p,
42
const u_int32_t open_flags = (create ? (DB_CREATE | DB_EXCL) : 0);
46
BDB_ERR (svn_fs_bdb__check_version());
47
BDB_ERR (db_create (&uuids, env, 0));
48
BDB_ERR (uuids->set_re_len (uuids, APR_UUID_FORMATTED_LENGTH));
50
error = uuids->open (SVN_BDB_OPEN_PARAMS (uuids, NULL),
52
open_flags | SVN_BDB_AUTO_COMMIT,
55
/* This is a temporary compatibility check; it creates the
56
UUIDs table if one does not already exist. */
57
if (error == ENOENT && (! create))
59
BDB_ERR (uuids->close (uuids, 0));
60
return svn_fs_bdb__open_uuids_table (uuids_p, env, TRUE);
67
char buffer[APR_UUID_FORMATTED_LENGTH + 1];
72
svn_fs_base__clear_dbt (&key);
74
key.size = sizeof (recno);
76
svn_fs_base__clear_dbt (&value);
78
value.size = sizeof (buffer) - 1;
81
apr_uuid_format (buffer, &uuid);
83
BDB_ERR (uuids->put (uuids, 0, &key, &value,
84
DB_APPEND | SVN_BDB_AUTO_COMMIT));
91
svn_error_t *svn_fs_bdb__get_uuid (svn_fs_t *fs,
97
base_fs_data_t *bfd = fs->fsap_data;
98
char buffer[APR_UUID_FORMATTED_LENGTH + 1];
99
DB *uuids = bfd->uuids;
103
svn_fs_base__clear_dbt (&key);
105
key.size = sizeof (idx);
107
svn_fs_base__clear_dbt (&value);
109
value.size = sizeof (buffer) - 1;
111
svn_fs_base__trail_debug (trail, "uuids", "get");
112
SVN_ERR (BDB_WRAP (fs, _("get repository uuid"),
113
uuids->get (uuids, trail->db_txn, &key, &value, 0)));
115
*uuid = apr_pstrmemdup (pool, value.data, value.size);
120
svn_error_t *svn_fs_bdb__set_uuid (svn_fs_t *fs,
126
base_fs_data_t *bfd = fs->fsap_data;
127
DB *uuids = bfd->uuids;
131
svn_fs_base__clear_dbt (&key);
133
key.size = sizeof (idx);
135
svn_fs_base__clear_dbt (&value);
136
value.size = strlen (uuid);
137
value.data = apr_pstrmemdup (pool, uuid, value.size + 1);
139
svn_fs_base__trail_debug (trail, "uuids", "put");
140
SVN_ERR (BDB_WRAP (fs, _("set repository uuid"),
141
uuids->put (uuids, trail->db_txn, &key, &value, 0)));