Win32: fix an incorrect error status being propagated to the caller in case
[svn/apache.git] / subversion / libsvn_client / revert.c
blobcec28f2de2dd017360261f5b1fa7e3b16c764c74
1 /*
2 * revert.c: wrapper around wc revert functionality.
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 /* ==================================================================== */
28 /*** Includes. ***/
30 #include "svn_path.h"
31 #include "svn_wc.h"
32 #include "svn_client.h"
33 #include "svn_dirent_uri.h"
34 #include "svn_hash.h"
35 #include "svn_pools.h"
36 #include "svn_error.h"
37 #include "svn_time.h"
38 #include "svn_config.h"
39 #include "client.h"
40 #include "private/svn_wc_private.h"
42 #include "svn_private_config.h"
45 /*** Code. ***/
47 struct revert_with_write_lock_baton {
48 const char *local_abspath;
49 svn_depth_t depth;
50 svn_boolean_t use_commit_times;
51 const apr_array_header_t *changelists;
52 svn_boolean_t clear_changelists;
53 svn_boolean_t metadata_only;
54 svn_boolean_t added_keep_local;
55 svn_client_ctx_t *ctx;
58 /* (Note: All arguments are in the baton above.)
60 Attempt to revert LOCAL_ABSPATH.
62 If DEPTH is svn_depth_empty, revert just the properties on the
63 directory; else if svn_depth_files, revert the properties and any
64 files immediately under the directory; else if
65 svn_depth_immediates, revert all of the preceding plus properties
66 on immediate subdirectories; else if svn_depth_infinity, revert
67 path and everything under it fully recursively.
69 CHANGELISTS is an array of const char * changelist names, used as a
70 restrictive filter on items reverted; that is, don't revert any
71 item unless it's a member of one of those changelists. If
72 CHANGELISTS is empty (or altogether NULL), no changelist filtering occurs.
74 Consult CTX to determine whether or not to revert timestamp to the
75 time of last commit ('use-commit-times = yes').
77 If PATH is unversioned, return SVN_ERR_UNVERSIONED_RESOURCE. */
78 static svn_error_t *
79 revert(void *baton, apr_pool_t *result_pool, apr_pool_t *scratch_pool)
81 struct revert_with_write_lock_baton *b = baton;
82 svn_error_t *err;
84 err = svn_wc_revert6(b->ctx->wc_ctx,
85 b->local_abspath,
86 b->depth,
87 b->use_commit_times,
88 b->changelists,
89 b->clear_changelists,
90 b->metadata_only,
91 b->added_keep_local,
92 b->ctx->cancel_func, b->ctx->cancel_baton,
93 b->ctx->notify_func2, b->ctx->notify_baton2,
94 scratch_pool);
96 if (err)
98 /* If target isn't versioned, just send a 'skip'
99 notification and move on. */
100 if (err->apr_err == SVN_ERR_ENTRY_NOT_FOUND
101 || err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE
102 || err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND)
104 if (b->ctx->notify_func2)
106 svn_wc_notify_t *notify;
108 notify = svn_wc_create_notify(b->local_abspath,
109 svn_wc_notify_skip,
110 scratch_pool);
112 notify->err = err;
114 b->ctx->notify_func2(b->ctx->notify_baton2,
115 notify, scratch_pool);
117 svn_error_clear(err);
119 else
120 return svn_error_trace(err);
123 return SVN_NO_ERROR;
127 svn_error_t *
128 svn_client_revert4(const apr_array_header_t *paths,
129 svn_depth_t depth,
130 const apr_array_header_t *changelists,
131 svn_boolean_t clear_changelists,
132 svn_boolean_t metadata_only,
133 svn_boolean_t added_keep_local,
134 svn_client_ctx_t *ctx,
135 apr_pool_t *pool)
137 apr_pool_t *iterpool;
138 svn_error_t *err = SVN_NO_ERROR;
139 int i;
140 svn_config_t *cfg;
141 svn_boolean_t use_commit_times;
142 struct revert_with_write_lock_baton baton;
144 /* Don't even attempt to modify the working copy if any of the
145 * targets look like URLs. URLs are invalid input. */
146 for (i = 0; i < paths->nelts; i++)
148 const char *path = APR_ARRAY_IDX(paths, i, const char *);
150 if (svn_path_is_url(path))
151 return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
152 _("'%s' is not a local path"), path);
155 cfg = ctx->config
156 ? svn_hash_gets(ctx->config, SVN_CONFIG_CATEGORY_CONFIG)
157 : NULL;
159 SVN_ERR(svn_config_get_bool(cfg, &use_commit_times,
160 SVN_CONFIG_SECTION_MISCELLANY,
161 SVN_CONFIG_OPTION_USE_COMMIT_TIMES,
162 FALSE));
164 iterpool = svn_pool_create(pool);
166 for (i = 0; i < paths->nelts; i++)
168 const char *path = APR_ARRAY_IDX(paths, i, const char *);
169 const char *local_abspath, *lock_target;
170 svn_boolean_t wc_root;
172 svn_pool_clear(iterpool);
174 /* See if we've been asked to cancel this operation. */
175 if ((ctx->cancel_func)
176 && ((err = ctx->cancel_func(ctx->cancel_baton))))
177 goto errorful;
179 err = svn_dirent_get_absolute(&local_abspath, path, iterpool);
180 if (err)
181 goto errorful;
183 baton.local_abspath = local_abspath;
184 baton.depth = depth;
185 baton.use_commit_times = use_commit_times;
186 baton.changelists = changelists;
187 baton.clear_changelists = clear_changelists;
188 baton.metadata_only = metadata_only;
189 baton.added_keep_local = added_keep_local;
190 baton.ctx = ctx;
192 err = svn_wc__is_wcroot(&wc_root, ctx->wc_ctx, local_abspath, iterpool);
193 if (err)
194 goto errorful;
195 lock_target = wc_root ? local_abspath
196 : svn_dirent_dirname(local_abspath, pool);
197 err = svn_wc__call_with_write_lock(revert, &baton, ctx->wc_ctx,
198 lock_target, FALSE,
199 iterpool, iterpool);
200 if (err)
201 goto errorful;
204 errorful:
207 /* Sleep to ensure timestamp integrity. */
208 const char *sleep_path = NULL;
210 /* Only specify a path if we are certain all paths are on the
211 same filesystem */
212 if (paths->nelts == 1)
213 sleep_path = APR_ARRAY_IDX(paths, 0, const char *);
215 svn_io_sleep_for_timestamps(sleep_path, iterpool);
218 svn_pool_destroy(iterpool);
220 return svn_error_trace(err);