~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/libsvn_fs_base/bdb/lock-tokens-table.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* lock-tokens-table.c : operations on the `lock-tokens' table
 
2
 *
 
3
 * ====================================================================
 
4
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 
5
 *
 
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.
 
11
 *
 
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
 * ====================================================================
 
16
 */
 
17
 
 
18
#include <string.h>
 
19
#include <assert.h>
 
20
#include "bdb_compat.h"
 
21
 
 
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"
 
33
 
 
34
 
 
35
int
 
36
svn_fs_bdb__open_lock_tokens_table (DB **lock_tokens_p,
 
37
                                    DB_ENV *env,
 
38
                                    svn_boolean_t create)
 
39
{
 
40
  const u_int32_t open_flags = (create ? (DB_CREATE | DB_EXCL) : 0);
 
41
  DB *lock_tokens;
 
42
  int error;
 
43
 
 
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,
 
49
                             0666);
 
50
 
 
51
  /* Create the table if it doesn't yet exist.  This is a form of
 
52
     automagical repository upgrading. */
 
53
  if (error == ENOENT && (! create))
 
54
    {
 
55
      BDB_ERR (lock_tokens->close (lock_tokens, 0));
 
56
      return svn_fs_bdb__open_lock_tokens_table (lock_tokens_p, env, TRUE);
 
57
    }
 
58
  BDB_ERR (error);
 
59
 
 
60
  *lock_tokens_p = lock_tokens;
 
61
  return 0;
 
62
}
 
63
 
 
64
 
 
65
svn_error_t *
 
66
svn_fs_bdb__lock_token_add (svn_fs_t *fs,
 
67
                            const char *path,
 
68
                            const char *lock_token,
 
69
                            trail_t *trail,
 
70
                            apr_pool_t *pool)
 
71
{
 
72
 
 
73
  base_fs_data_t *bfd = fs->fsap_data;
 
74
  DBT key, value;
 
75
 
 
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,
 
81
                                           &key, &value, 0)));
 
82
 
 
83
  return SVN_NO_ERROR;
 
84
}
 
85
 
 
86
 
 
87
svn_error_t *
 
88
svn_fs_bdb__lock_token_delete (svn_fs_t *fs,
 
89
                               const char *path,
 
90
                               trail_t *trail,
 
91
                               apr_pool_t *pool)
 
92
{
 
93
  base_fs_data_t *bfd = fs->fsap_data;
 
94
  DBT key;
 
95
  int db_err;
 
96
 
 
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));
 
103
  
 
104
  return SVN_NO_ERROR;
 
105
}
 
106
 
 
107
 
 
108
svn_error_t *
 
109
svn_fs_bdb__lock_token_get (const char **lock_token_p,
 
110
                            svn_fs_t *fs,
 
111
                            const char *path,
 
112
                            trail_t *trail,
 
113
                            apr_pool_t *pool)
 
114
{
 
115
  base_fs_data_t *bfd = fs->fsap_data;
 
116
  DBT key, value;
 
117
  svn_error_t *err;
 
118
  svn_lock_t *lock;
 
119
  const char *lock_token;
 
120
  int db_err;
 
121
 
 
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),
 
126
                                  0);
 
127
  svn_fs_base__track_dbt (&value, pool);
 
128
 
 
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));
 
132
 
 
133
  lock_token = apr_pstrmemdup (pool, value.data, value.size);
 
134
 
 
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)))
 
140
    {
 
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);
 
144
      if (delete_err)
 
145
        svn_error_compose (err, delete_err);
 
146
      return err;
 
147
    }
 
148
  else if (err)
 
149
    return err;
 
150
 
 
151
  *lock_token_p = lock_token;
 
152
  return SVN_NO_ERROR;
 
153
}