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"
34 #include "private/svn_fs_util.h"
38 svn_fs_bdb__open_lock_tokens_table(DB
**lock_tokens_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(&lock_tokens
, env
, 0));
48 error
= (lock_tokens
->open
)(SVN_BDB_OPEN_PARAMS(lock_tokens
, NULL
),
49 "lock-tokens", 0, DB_BTREE
,
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
);
61 *lock_tokens_p
= lock_tokens
;
67 svn_fs_bdb__lock_token_add(svn_fs_t
*fs
,
69 const char *lock_token
,
74 base_fs_data_t
*bfd
= fs
->fsap_data
;
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
,
89 svn_fs_bdb__lock_token_delete(svn_fs_t
*fs
,
94 base_fs_data_t
*bfd
= fs
->fsap_data
;
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
));
110 svn_fs_bdb__lock_token_get(const char **lock_token_p
,
116 base_fs_data_t
*bfd
= fs
->fsap_data
;
120 const char *lock_token
;
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
);
146 svn_error_compose(err
, delete_err
);
152 *lock_token_p
= lock_token
;