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
),
54 /* This is a temporary compatibility check; it creates the
55 UUIDs table if one does not already exist. */
56 if (error
== ENOENT
&& (! create
))
58 BDB_ERR(uuids
->close(uuids
, 0));
59 return svn_fs_bdb__open_uuids_table(uuids_p
, env
, TRUE
);
66 char buffer
[APR_UUID_FORMATTED_LENGTH
+ 1];
71 svn_fs_base__clear_dbt(&key
);
73 key
.size
= sizeof(recno
);
75 key
.flags
|= DB_DBT_USERMEM
;
77 svn_fs_base__clear_dbt(&value
);
79 value
.size
= sizeof(buffer
) - 1;
82 apr_uuid_format(buffer
, &uuid
);
84 BDB_ERR(uuids
->put(uuids
, 0, &key
, &value
, DB_APPEND
));
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;
110 value
.ulen
= value
.size
;
111 value
.flags
|= DB_DBT_USERMEM
;
113 svn_fs_base__trail_debug(trail
, "uuids", "get");
114 SVN_ERR(BDB_WRAP(fs
, _("get repository uuid"),
115 uuids
->get(uuids
, trail
->db_txn
, &key
, &value
, 0)));
117 *uuid
= apr_pstrmemdup(pool
, value
.data
, value
.size
);
122 svn_error_t
*svn_fs_bdb__set_uuid(svn_fs_t
*fs
,
128 base_fs_data_t
*bfd
= fs
->fsap_data
;
129 DB
*uuids
= bfd
->uuids
;
133 svn_fs_base__clear_dbt(&key
);
135 key
.size
= sizeof(idx
);
137 svn_fs_base__clear_dbt(&value
);
138 value
.size
= strlen(uuid
);
139 value
.data
= apr_pstrmemdup(pool
, uuid
, value
.size
+ 1);
141 svn_fs_base__trail_debug(trail
, "uuids", "put");
142 SVN_ERR(BDB_WRAP(fs
, _("set repository uuid"),
143 uuids
->put(uuids
, trail
->db_txn
, &key
, &value
, 0)));