aboutsummaryrefslogtreecommitdiff
path: root/subversion/libsvn_client/cleanup.c
blob: e3fffdcaf0db436c295afd98965e0ef348ba07b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
 * cleanup.c:  wrapper around wc cleanup functionality.
 *
 * ====================================================================
 *    Licensed to the Apache Software Foundation (ASF) under one
 *    or more contributor license agreements.  See the NOTICE file
 *    distributed with this work for additional information
 *    regarding copyright ownership.  The ASF licenses this file
 *    to you under the Apache License, Version 2.0 (the
 *    "License"); you may not use this file except in compliance
 *    with the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing,
 *    software distributed under the License is distributed on an
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *    KIND, either express or implied.  See the License for the
 *    specific language governing permissions and limitations
 *    under the License.
 * ====================================================================
 */

/* ==================================================================== */



/*** Includes. ***/

#include "svn_time.h"
#include "svn_wc.h"
#include "svn_client.h"
#include "svn_config.h"
#include "svn_dirent_uri.h"
#include "svn_hash.h"
#include "svn_path.h"
#include "svn_pools.h"
#include "client.h"
#include "svn_props.h"

#include "svn_private_config.h"
#include "private/svn_wc_private.h"


/*** Code. ***/

struct cleanup_status_walk_baton
{
  svn_boolean_t break_locks;
  svn_boolean_t fix_timestamps;
  svn_boolean_t clear_dav_cache;
  svn_boolean_t vacuum_pristines;
  svn_boolean_t remove_unversioned_items;
  svn_boolean_t remove_ignored_items;
  svn_boolean_t include_externals;
  svn_client_ctx_t *ctx;
};

/* Forward declararion. */
static svn_error_t *
cleanup_status_walk(void *baton,
                    const char *local_abspath,
                    const svn_wc_status3_t *status,
                    apr_pool_t *scratch_pool);

static svn_error_t *
do_cleanup(const char *local_abspath,
           svn_boolean_t break_locks,
           svn_boolean_t fix_timestamps,
           svn_boolean_t clear_dav_cache,
           svn_boolean_t vacuum_pristines,
           svn_boolean_t remove_unversioned_items,
           svn_boolean_t remove_ignored_items,
           svn_boolean_t include_externals,
           svn_client_ctx_t *ctx,
           apr_pool_t *scratch_pool)
{
  SVN_ERR(svn_wc_cleanup4(ctx->wc_ctx,
                          local_abspath,
                          break_locks,
                          fix_timestamps,
                          clear_dav_cache,
                          vacuum_pristines,
                          ctx->cancel_func, ctx->cancel_baton,
                          ctx->notify_func2, ctx->notify_baton2,
                          scratch_pool));

  if (fix_timestamps)
    svn_io_sleep_for_timestamps(local_abspath, scratch_pool);

  if (remove_unversioned_items || remove_ignored_items || include_externals)
    {
      struct cleanup_status_walk_baton b;
      apr_array_header_t *ignores;

      b.break_locks = break_locks;
      b.fix_timestamps = fix_timestamps;
      b.clear_dav_cache = clear_dav_cache;
      b.vacuum_pristines = vacuum_pristines;
      b.remove_unversioned_items = remove_unversioned_items;
      b.remove_ignored_items = remove_ignored_items;
      b.include_externals = include_externals;
      b.ctx = ctx;

      SVN_ERR(svn_wc_get_default_ignores(&ignores, ctx->config, scratch_pool));

      SVN_WC__CALL_WITH_WRITE_LOCK(
              svn_wc_walk_status(ctx->wc_ctx, local_abspath,
                                 svn_depth_infinity,
                                 TRUE,  /* get all */
                                 remove_ignored_items,
                                 TRUE,  /* ignore textmods */
                                 ignores,
                                 cleanup_status_walk, &b,
                                 ctx->cancel_func,
                                 ctx->cancel_baton,
                                 scratch_pool),
              ctx->wc_ctx,
              local_abspath,
              FALSE /* lock_anchor */,
              scratch_pool);
    }

  return SVN_NO_ERROR;
}


/* An implementation of svn_wc_status_func4_t. */
static svn_error_t *
cleanup_status_walk(void *baton,
                    const char *local_abspath,
                    const svn_wc_status3_t *status,
                    apr_pool_t *scratch_pool)
{
  struct cleanup_status_walk_baton *b = baton;
  svn_node_kind_t kind_on_disk;
  svn_wc_notify_t *notify;

  if (status->node_status == svn_wc_status_external && b->include_externals)
    {
      svn_error_t *err;

      SVN_ERR(svn_io_check_path(local_abspath, &kind_on_disk, scratch_pool));
      if (kind_on_disk == svn_node_dir)
        {
          if (b->ctx->notify_func2)
            {
              notify = svn_wc_create_notify(local_abspath,
                                            svn_wc_notify_cleanup_external,
                                            scratch_pool);
              b->ctx->notify_func2(b->ctx->notify_baton2, notify,
                                   scratch_pool);
            }

          err = do_cleanup(local_abspath,
                           b->break_locks,
                           b->fix_timestamps,
                           b->clear_dav_cache,
                           b->vacuum_pristines,
                           b->remove_unversioned_items,
                           b->remove_ignored_items,
                           TRUE /* include_externals */,
                           b->ctx, scratch_pool);
          if (err && err->apr_err == SVN_ERR_WC_NOT_WORKING_COPY)
            {
              svn_error_clear(err);
              return SVN_NO_ERROR;
            }
          else
            SVN_ERR(err);
        }

      return SVN_NO_ERROR;
    }

  if (status->node_status == svn_wc_status_ignored)
    {
      if (!b->remove_ignored_items)
        return SVN_NO_ERROR;
    }
  else if (status->node_status == svn_wc_status_unversioned)
    {
      if (!b->remove_unversioned_items)
        return SVN_NO_ERROR;
    }
  else
    return SVN_NO_ERROR;

  SVN_ERR(svn_io_check_path(local_abspath, &kind_on_disk, scratch_pool));
  switch (kind_on_disk)
    {
      case svn_node_file:
      case svn_node_symlink:
        SVN_ERR(svn_io_remove_file2(local_abspath, FALSE, scratch_pool));
        break;
      case svn_node_dir:
        SVN_ERR(svn_io_remove_dir2(local_abspath, FALSE,
                                   b->ctx->cancel_func, b->ctx->cancel_baton,
                                   scratch_pool));
        break;
      case svn_node_none:
      default:
        return SVN_NO_ERROR;
    }

  if (b->ctx->notify_func2)
    {
      notify = svn_wc_create_notify(local_abspath, svn_wc_notify_delete,
                                    scratch_pool);
      notify->kind = kind_on_disk;
      b->ctx->notify_func2(b->ctx->notify_baton2, notify, scratch_pool);
    }

  return SVN_NO_ERROR;
}

svn_error_t *
svn_client_cleanup2(const char *dir_abspath,
                    svn_boolean_t break_locks,
                    svn_boolean_t fix_recorded_timestamps,
                    svn_boolean_t clear_dav_cache,
                    svn_boolean_t vacuum_pristines,
                    svn_boolean_t include_externals,
                    svn_client_ctx_t *ctx,
                    apr_pool_t *scratch_pool)
{
  SVN_ERR_ASSERT(svn_dirent_is_absolute(dir_abspath));

  SVN_ERR(do_cleanup(dir_abspath,
                     break_locks,
                     fix_recorded_timestamps,
                     clear_dav_cache,
                     vacuum_pristines,
                     FALSE /* remove_unversioned_items */,
                     FALSE /* remove_ignored_items */,
                     include_externals,
                     ctx, scratch_pool));

  return SVN_NO_ERROR;
}

svn_error_t *
svn_client_vacuum(const char *dir_abspath,
                  svn_boolean_t remove_unversioned_items,
                  svn_boolean_t remove_ignored_items,
                  svn_boolean_t fix_recorded_timestamps,
                  svn_boolean_t vacuum_pristines,
                  svn_boolean_t include_externals,
                  svn_client_ctx_t *ctx,
                  apr_pool_t *scratch_pool)
{
  SVN_ERR_ASSERT(svn_dirent_is_absolute(dir_abspath));

  SVN_ERR(do_cleanup(dir_abspath,
                     FALSE /* break_locks */,
                     fix_recorded_timestamps,
                     FALSE /* clear_dav_cache */,
                     vacuum_pristines,
                     remove_unversioned_items,
                     remove_ignored_items,
                     include_externals,
                     ctx, scratch_pool));

  return SVN_NO_ERROR;
}