Mark many merge tests as skip-against-old-server.
[svn.git] / subversion / libsvn_fs_base / bdb / lock-tokens-table.c
bloba6746a0fcd2dce940fa14d11389aed4bbf551bd9
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 * ====================================================================
18 #include <string.h>
19 #include <assert.h>
20 #include "bdb_compat.h"
22 #include "svn_pools.h"
23 #include "dbt.h"
24 #include "../err.h"
25 #include "../fs.h"
26 #include "../util/skel.h"
27 #include "../util/fs_skels.h"
28 #include "../trail.h"
29 #include "../../libsvn_fs/fs-loader.h"
30 #include "bdb-err.h"
31 #include "lock-tokens-table.h"
32 #include "locks-table.h"
34 #include "private/svn_fs_util.h"
37 int
38 svn_fs_bdb__open_lock_tokens_table(DB **lock_tokens_p,
39 DB_ENV *env,
40 svn_boolean_t create)
42 const u_int32_t open_flags = (create ? (DB_CREATE | DB_EXCL) : 0);
43 DB *lock_tokens;
44 int error;
46 BDB_ERR(svn_fs_bdb__check_version());
47 BDB_ERR(db_create(&lock_tokens, env, 0));
48 error = (lock_tokens->open)(SVN_BDB_OPEN_PARAMS(lock_tokens, NULL),
49 "lock-tokens", 0, DB_BTREE,
50 open_flags, 0666);
52 /* Create the table if it doesn't yet exist. This is a form of
53 automagical repository upgrading. */
54 if (error == ENOENT && (! create))
56 BDB_ERR(lock_tokens->close(lock_tokens, 0));
57 return svn_fs_bdb__open_lock_tokens_table(lock_tokens_p, env, TRUE);
59 BDB_ERR(error);
61 *lock_tokens_p = lock_tokens;
62 return 0;
66 svn_error_t *
67 svn_fs_bdb__lock_token_add(svn_fs_t *fs,
68 const char *path,
69 const char *lock_token,
70 trail_t *trail,
71 apr_pool_t *pool)
74 base_fs_data_t *bfd = fs->fsap_data;
75 DBT key, value;
77 svn_fs_base__str_to_dbt(&key, path);
78 svn_fs_base__str_to_dbt(&value, lock_token);
79 svn_fs_base__trail_debug(trail, "lock-tokens", "add");
80 SVN_ERR(BDB_WRAP(fs, "storing lock token record",
81 bfd->lock_tokens->put(bfd->lock_tokens, trail->db_txn,
82 &key, &value, 0)));
84 return SVN_NO_ERROR;
88 svn_error_t *
89 svn_fs_bdb__lock_token_delete(svn_fs_t *fs,
90 const char *path,
91 trail_t *trail,
92 apr_pool_t *pool)
94 base_fs_data_t *bfd = fs->fsap_data;
95 DBT key;
96 int db_err;
98 svn_fs_base__str_to_dbt(&key, path);
99 svn_fs_base__trail_debug(trail, "lock-tokens", "del");
100 db_err = bfd->lock_tokens->del(bfd->lock_tokens, trail->db_txn, &key, 0);
101 if (db_err == DB_NOTFOUND)
102 return SVN_FS__ERR_NO_SUCH_LOCK(fs, path);
103 SVN_ERR(BDB_WRAP(fs, "deleting entry from 'lock-tokens' table", db_err));
105 return SVN_NO_ERROR;
109 svn_error_t *
110 svn_fs_bdb__lock_token_get(const char **lock_token_p,
111 svn_fs_t *fs,
112 const char *path,
113 trail_t *trail,
114 apr_pool_t *pool)
116 base_fs_data_t *bfd = fs->fsap_data;
117 DBT key, value;
118 svn_error_t *err;
119 svn_lock_t *lock;
120 const char *lock_token;
121 int db_err;
123 svn_fs_base__trail_debug(trail, "lock-tokens", "get");
124 db_err = bfd->lock_tokens->get(bfd->lock_tokens, trail->db_txn,
125 svn_fs_base__str_to_dbt(&key, path),
126 svn_fs_base__result_dbt(&value),
128 svn_fs_base__track_dbt(&value, pool);
130 if (db_err == DB_NOTFOUND)
131 return SVN_FS__ERR_NO_SUCH_LOCK(fs, path);
132 SVN_ERR(BDB_WRAP(fs, "reading lock token", db_err));
134 lock_token = apr_pstrmemdup(pool, value.data, value.size);
136 /* Make sure the token still points to an existing, non-expired
137 lock, by doing a lookup in the `locks' table. */
138 err = svn_fs_bdb__lock_get(&lock, fs, lock_token, trail, pool);
139 if (err && ((err->apr_err == SVN_ERR_FS_LOCK_EXPIRED)
140 || (err->apr_err == SVN_ERR_FS_BAD_LOCK_TOKEN)))
142 /* If `locks' doesn't have the lock, then we should lose it too. */
143 svn_error_t *delete_err;
144 delete_err = svn_fs_bdb__lock_token_delete(fs, path, trail, pool);
145 if (delete_err)
146 svn_error_compose(err, delete_err);
147 return err;
149 else if (err)
150 return err;
152 *lock_token_p = lock_token;
153 return SVN_NO_ERROR;