1/* uuid.c : operations on repository uuids 2 * 3 * ==================================================================== 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 * ==================================================================== 21 */ 22 23#include "svn_pools.h" 24#include "fs.h" 25#include "trail.h" 26#include "err.h" 27#include "uuid.h" 28#include "bdb/uuids-table.h" 29#include "../libsvn_fs/fs-loader.h" 30 31#include "private/svn_fs_util.h" 32 33 34struct get_uuid_args 35{ 36 int idx; 37 const char **uuid; 38}; 39 40 41static svn_error_t * 42txn_body_get_uuid(void *baton, trail_t *trail) 43{ 44 struct get_uuid_args *args = baton; 45 return svn_fs_bdb__get_uuid(trail->fs, args->idx, args->uuid, 46 trail, trail->pool); 47} 48 49 50svn_error_t * 51svn_fs_base__populate_uuid(svn_fs_t *fs, 52 apr_pool_t *scratch_pool) 53{ 54 55 SVN_ERR(svn_fs__check_fs(fs, TRUE)); 56 57 /* We hit the database. */ 58 { 59 const char *uuid; 60 struct get_uuid_args args; 61 62 args.idx = 1; 63 args.uuid = &uuid; 64 SVN_ERR(svn_fs_base__retry_txn(fs, txn_body_get_uuid, &args, 65 FALSE, scratch_pool)); 66 67 if (uuid) 68 { 69 /* Toss what we find into the cache. */ 70 fs->uuid = apr_pstrdup(fs->pool, uuid); 71 } 72 } 73 74 return SVN_NO_ERROR; 75} 76 77 78struct set_uuid_args 79{ 80 int idx; 81 const char *uuid; 82}; 83 84 85static svn_error_t * 86txn_body_set_uuid(void *baton, trail_t *trail) 87{ 88 struct set_uuid_args *args = baton; 89 return svn_fs_bdb__set_uuid(trail->fs, args->idx, args->uuid, 90 trail, trail->pool); 91} 92 93 94svn_error_t * 95svn_fs_base__set_uuid(svn_fs_t *fs, 96 const char *uuid, 97 apr_pool_t *pool) 98{ 99 struct set_uuid_args args; 100 101 SVN_ERR(svn_fs__check_fs(fs, TRUE)); 102 103 if (! uuid) 104 uuid = svn_uuid_generate(pool); 105 106 args.idx = 1; 107 args.uuid = uuid; 108 SVN_ERR(svn_fs_base__retry_txn(fs, txn_body_set_uuid, &args, TRUE, pool)); 109 110 /* Toss our value into the cache. */ 111 if (uuid) 112 fs->uuid = apr_pstrdup(fs->pool, uuid); 113 114 return SVN_NO_ERROR; 115} 116 117