~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/libsvn_fs_base/bdb/uuids-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
/* uuids-table.c : operations on the `uuids' 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 <apr_uuid.h>
 
19
 
 
20
#include "bdb_compat.h"
 
21
#include "svn_fs.h"
 
22
#include "../fs.h"
 
23
#include "../err.h"
 
24
#include "dbt.h"
 
25
#include "../trail.h"
 
26
#include "../../libsvn_fs/fs-loader.h"
 
27
#include "bdb-err.h"
 
28
#include "uuids-table.h"
 
29
 
 
30
#include "svn_private_config.h"
 
31
 
 
32
 
 
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. ***/
 
36
 
 
37
int
 
38
svn_fs_bdb__open_uuids_table (DB **uuids_p,
 
39
                              DB_ENV *env,
 
40
                              svn_boolean_t create)
 
41
{
 
42
  const u_int32_t open_flags = (create ? (DB_CREATE | DB_EXCL) : 0);
 
43
  DB *uuids;
 
44
  int error;
 
45
 
 
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));
 
49
 
 
50
  error = uuids->open (SVN_BDB_OPEN_PARAMS (uuids, NULL),
 
51
                       "uuids", 0, DB_RECNO,
 
52
                       open_flags | SVN_BDB_AUTO_COMMIT,
 
53
                       0666);
 
54
 
 
55
  /* This is a temporary compatibility check; it creates the
 
56
     UUIDs table if one does not already exist. */
 
57
  if (error == ENOENT && (! create))
 
58
    {
 
59
      BDB_ERR (uuids->close (uuids, 0));
 
60
      return svn_fs_bdb__open_uuids_table (uuids_p, env, TRUE);
 
61
    }
 
62
 
 
63
  BDB_ERR (error);
 
64
 
 
65
  if (create)
 
66
    {
 
67
      char buffer[APR_UUID_FORMATTED_LENGTH + 1];
 
68
      DBT key, value;
 
69
      apr_uuid_t uuid;
 
70
      int recno = 0;
 
71
 
 
72
      svn_fs_base__clear_dbt (&key);
 
73
      key.data = &recno;
 
74
      key.size = sizeof (recno);
 
75
 
 
76
      svn_fs_base__clear_dbt (&value);
 
77
      value.data = buffer;
 
78
      value.size = sizeof (buffer) - 1;
 
79
 
 
80
      apr_uuid_get (&uuid);
 
81
      apr_uuid_format (buffer, &uuid);
 
82
 
 
83
      BDB_ERR (uuids->put (uuids, 0, &key, &value,
 
84
                           DB_APPEND | SVN_BDB_AUTO_COMMIT));
 
85
    }
 
86
 
 
87
  *uuids_p = uuids;
 
88
  return 0;
 
89
}
 
90
 
 
91
svn_error_t *svn_fs_bdb__get_uuid (svn_fs_t *fs,
 
92
                                   int idx,
 
93
                                   const char **uuid,
 
94
                                   trail_t *trail,
 
95
                                   apr_pool_t *pool)
 
96
{
 
97
  base_fs_data_t *bfd = fs->fsap_data;
 
98
  char buffer[APR_UUID_FORMATTED_LENGTH + 1];
 
99
  DB *uuids = bfd->uuids;
 
100
  DBT key;
 
101
  DBT value;
 
102
 
 
103
  svn_fs_base__clear_dbt (&key);
 
104
  key.data = &idx;
 
105
  key.size = sizeof (idx);
 
106
 
 
107
  svn_fs_base__clear_dbt (&value);
 
108
  value.data = buffer;
 
109
  value.size = sizeof (buffer) - 1;
 
110
 
 
111
  svn_fs_base__trail_debug (trail, "uuids", "get");
 
112
  SVN_ERR (BDB_WRAP (fs, _("get repository uuid"),
 
113
                     uuids->get (uuids, trail->db_txn, &key, &value, 0)));
 
114
 
 
115
  *uuid = apr_pstrmemdup (pool, value.data, value.size);
 
116
 
 
117
  return SVN_NO_ERROR;
 
118
}
 
119
 
 
120
svn_error_t *svn_fs_bdb__set_uuid (svn_fs_t *fs,
 
121
                                   int idx,
 
122
                                   const char *uuid,
 
123
                                   trail_t *trail,
 
124
                                   apr_pool_t *pool)
 
125
{
 
126
  base_fs_data_t *bfd = fs->fsap_data;
 
127
  DB *uuids = bfd->uuids;
 
128
  DBT key;
 
129
  DBT value;
 
130
 
 
131
  svn_fs_base__clear_dbt (&key);
 
132
  key.data = &idx;
 
133
  key.size = sizeof (idx);
 
134
 
 
135
  svn_fs_base__clear_dbt (&value);
 
136
  value.size = strlen (uuid);
 
137
  value.data = apr_pstrmemdup (pool, uuid, value.size + 1);
 
138
 
 
139
  svn_fs_base__trail_debug (trail, "uuids", "put");
 
140
  SVN_ERR (BDB_WRAP (fs, _("set repository uuid"),
 
141
                     uuids->put (uuids, trail->db_txn, &key, &value, 0)));
 
142
 
 
143
  return SVN_NO_ERROR;
 
144
}