Win32: fix an incorrect error status being propagated to the caller in case
[svn/apache.git] / subversion / libsvn_wc / context.c
blob4bf236992c4f0a8dbab4d67db825fb1fdbead148
1 /*
2 * context.c: routines for managing a working copy context
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 * ====================================================================
24 #include <apr_pools.h>
26 #include "svn_types.h"
27 #include "svn_pools.h"
28 #include "svn_dirent_uri.h"
29 #include "svn_path.h"
31 #include "wc.h"
32 #include "wc_db.h"
34 #include "svn_private_config.h"
38 /* APR cleanup function used to explicitly close any of our dependent
39 data structures before we disappear ourselves. */
40 static apr_status_t
41 close_ctx_apr(void *data)
43 svn_wc_context_t *ctx = data;
45 if (ctx->close_db_on_destroy)
47 svn_error_t *err = svn_wc__db_close(ctx->db);
48 if (err)
50 int result = err->apr_err;
51 svn_error_clear(err);
52 return result;
56 return APR_SUCCESS;
60 svn_error_t *
61 svn_wc_context_create(svn_wc_context_t **wc_ctx,
62 const svn_config_t *config,
63 apr_pool_t *result_pool,
64 apr_pool_t *scratch_pool)
66 svn_wc_context_t *ctx = apr_pcalloc(result_pool, sizeof(*ctx));
68 /* Create the state_pool, and open up a wc_db in it.
69 * Since config contains a private mutable member but C doesn't support
70 * we need to make it writable */
71 ctx->state_pool = result_pool;
72 SVN_ERR(svn_wc__db_open(&ctx->db, (svn_config_t *)config,
73 FALSE, TRUE, ctx->state_pool, scratch_pool));
74 ctx->close_db_on_destroy = TRUE;
76 apr_pool_cleanup_register(result_pool, ctx, close_ctx_apr,
77 apr_pool_cleanup_null);
79 *wc_ctx = ctx;
81 return SVN_NO_ERROR;
85 svn_error_t *
86 svn_wc__context_create_with_db(svn_wc_context_t **wc_ctx,
87 svn_config_t *config,
88 svn_wc__db_t *db,
89 apr_pool_t *result_pool)
91 svn_wc_context_t *ctx = apr_pcalloc(result_pool, sizeof(*ctx));
93 /* Create the state pool. We don't put the wc_db in it, because it's
94 already open in a separate pool somewhere. We also won't close the
95 wc_db when we destroy the context, since it's not ours to close. */
96 ctx->state_pool = result_pool;
97 ctx->db = db;
98 ctx->close_db_on_destroy = FALSE;
100 apr_pool_cleanup_register(result_pool, ctx, close_ctx_apr,
101 apr_pool_cleanup_null);
103 *wc_ctx = ctx;
105 return SVN_NO_ERROR;
109 svn_error_t *
110 svn_wc_context_destroy(svn_wc_context_t *wc_ctx)
112 /* We added a cleanup when creating; just run it now to close the context. */
113 apr_pool_cleanup_run(wc_ctx->state_pool, wc_ctx, close_ctx_apr);
115 return SVN_NO_ERROR;