1
/* lock-tokens-table.c : operations on the `lock-tokens' 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"
22
#include "svn_pools.h"
26
#include "../util/skel.h"
27
#include "../util/fs_skels.h"
29
#include "../../libsvn_fs/fs-loader.h"
31
#include "lock-tokens-table.h"
32
#include "locks-table.h"
36
svn_fs_bdb__open_lock_tokens_table (DB **lock_tokens_p,
40
const u_int32_t open_flags = (create ? (DB_CREATE | DB_EXCL) : 0);
44
BDB_ERR (svn_fs_bdb__check_version());
45
BDB_ERR (db_create (&lock_tokens, env, 0));
46
error = lock_tokens->open (SVN_BDB_OPEN_PARAMS(lock_tokens, NULL),
47
"lock-tokens", 0, DB_BTREE,
48
open_flags | SVN_BDB_AUTO_COMMIT,
51
/* Create the table if it doesn't yet exist. This is a form of
52
automagical repository upgrading. */
53
if (error == ENOENT && (! create))
55
BDB_ERR (lock_tokens->close (lock_tokens, 0));
56
return svn_fs_bdb__open_lock_tokens_table (lock_tokens_p, env, TRUE);
60
*lock_tokens_p = lock_tokens;
66
svn_fs_bdb__lock_token_add (svn_fs_t *fs,
68
const char *lock_token,
73
base_fs_data_t *bfd = fs->fsap_data;
76
svn_fs_base__str_to_dbt (&key, path);
77
svn_fs_base__str_to_dbt (&value, lock_token);
78
svn_fs_base__trail_debug (trail, "lock-tokens", "add");
79
SVN_ERR (BDB_WRAP (fs, "storing lock token record",
80
bfd->lock_tokens->put (bfd->lock_tokens, trail->db_txn,
88
svn_fs_bdb__lock_token_delete (svn_fs_t *fs,
93
base_fs_data_t *bfd = fs->fsap_data;
97
svn_fs_base__str_to_dbt (&key, path);
98
svn_fs_base__trail_debug (trail, "lock-tokens", "del");
99
db_err = bfd->lock_tokens->del (bfd->lock_tokens, trail->db_txn, &key, 0);
100
if (db_err == DB_NOTFOUND)
101
return svn_fs_base__err_no_such_lock (fs, path);
102
SVN_ERR (BDB_WRAP (fs, "deleting entry from 'lock-tokens' table", db_err));
109
svn_fs_bdb__lock_token_get (const char **lock_token_p,
115
base_fs_data_t *bfd = fs->fsap_data;
119
const char *lock_token;
122
svn_fs_base__trail_debug (trail, "lock-tokens", "get");
123
db_err = bfd->lock_tokens->get (bfd->lock_tokens, trail->db_txn,
124
svn_fs_base__str_to_dbt (&key, path),
125
svn_fs_base__result_dbt (&value),
127
svn_fs_base__track_dbt (&value, pool);
129
if (db_err == DB_NOTFOUND)
130
return svn_fs_base__err_no_such_lock (fs, path);
131
SVN_ERR (BDB_WRAP (fs, "reading lock token", db_err));
133
lock_token = apr_pstrmemdup (pool, value.data, value.size);
135
/* Make sure the token still points to an existing, non-expired
136
lock, by doing a lookup in the `locks' table. */
137
err = svn_fs_bdb__lock_get (&lock, fs, lock_token, trail, pool);
138
if (err && ((err->apr_err == SVN_ERR_FS_LOCK_EXPIRED)
139
|| (err->apr_err == SVN_ERR_FS_BAD_LOCK_TOKEN)))
141
/* If `locks' doesn't have the lock, then we should lose it too. */
142
svn_error_t *delete_err;
143
delete_err = svn_fs_bdb__lock_token_delete (fs, path, trail, pool);
145
svn_error_compose (err, delete_err);
151
*lock_token_p = lock_token;