1251881Speter/*
2251881Speter * unlock-cmd.c -- Unlock a working copy path.
3251881Speter *
4251881Speter * ====================================================================
5251881Speter *    Licensed to the Apache Software Foundation (ASF) under one
6251881Speter *    or more contributor license agreements.  See the NOTICE file
7251881Speter *    distributed with this work for additional information
8251881Speter *    regarding copyright ownership.  The ASF licenses this file
9251881Speter *    to you under the Apache License, Version 2.0 (the
10251881Speter *    "License"); you may not use this file except in compliance
11251881Speter *    with the License.  You may obtain a copy of the License at
12251881Speter *
13251881Speter *      http://www.apache.org/licenses/LICENSE-2.0
14251881Speter *
15251881Speter *    Unless required by applicable law or agreed to in writing,
16251881Speter *    software distributed under the License is distributed on an
17251881Speter *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18251881Speter *    KIND, either express or implied.  See the License for the
19251881Speter *    specific language governing permissions and limitations
20251881Speter *    under the License.
21251881Speter * ====================================================================
22251881Speter */
23251881Speter
24251881Speter/* ==================================================================== */
25251881Speter
26251881Speter
27251881Speter
28251881Speter/*** Includes. ***/
29251881Speter
30251881Speter#include "svn_path.h"
31251881Speter#include "svn_pools.h"
32251881Speter#include "svn_client.h"
33251881Speter#include "svn_error_codes.h"
34251881Speter#include "svn_error.h"
35251881Speter#include "svn_cmdline.h"
36251881Speter#include "cl.h"
37251881Speter#include "svn_private_config.h"
38251881Speter
39251881Speter
40251881Speter/*** Code. ***/
41251881Speter
42298845Sdim/* Baton for notify_unlock_handler */
43298845Sdimstruct notify_unlock_baton_t
44298845Sdim{
45298845Sdim  void *inner_baton;
46298845Sdim  svn_wc_notify_func2_t inner_notify;
47298845Sdim  svn_boolean_t had_failure;
48298845Sdim};
49251881Speter
50298845Sdim/* Implements svn_wc_notify_func2_t for svn_cl__unlock */
51298845Sdimstatic void
52298845Sdimnotify_unlock_handler(void *baton,
53298845Sdim                      const svn_wc_notify_t *notify,
54298845Sdim                      apr_pool_t *scratch_pool)
55298845Sdim{
56298845Sdim  struct notify_unlock_baton_t *nub = baton;
57298845Sdim
58298845Sdim  if (notify->action == svn_wc_notify_failed_unlock)
59298845Sdim    nub->had_failure = TRUE;
60298845Sdim
61298845Sdim  if (nub->inner_notify)
62298845Sdim    nub->inner_notify(nub->inner_baton, notify, scratch_pool);
63298845Sdim}
64298845Sdim
65298845Sdim
66251881Speter/* This implements the `svn_opt_subcommand_t' interface. */
67251881Spetersvn_error_t *
68251881Spetersvn_cl__unlock(apr_getopt_t *os,
69251881Speter               void *baton,
70251881Speter               apr_pool_t *scratch_pool)
71251881Speter{
72251881Speter  svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
73251881Speter  svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
74251881Speter  apr_array_header_t *targets;
75298845Sdim  struct notify_unlock_baton_t nub;
76251881Speter
77251881Speter  SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
78251881Speter                                                      opt_state->targets,
79251881Speter                                                      ctx, FALSE,
80251881Speter                                                      scratch_pool));
81251881Speter
82251881Speter  /* We don't support unlock on directories, so "." is not relevant. */
83251881Speter  if (! targets->nelts)
84251881Speter    return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
85251881Speter
86251881Speter  SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, scratch_pool));
87251881Speter
88251881Speter  SVN_ERR(svn_cl__assert_homogeneous_target_type(targets));
89251881Speter
90298845Sdim  nub.inner_notify = ctx->notify_func2;
91298845Sdim  nub.inner_baton = ctx->notify_baton2;
92298845Sdim  nub.had_failure = FALSE;
93298845Sdim
94298845Sdim  ctx->notify_func2 = notify_unlock_handler;
95298845Sdim  ctx->notify_baton2 = &nub;
96298845Sdim
97298845Sdim  SVN_ERR(svn_client_unlock(targets, opt_state->force, ctx, scratch_pool));
98298845Sdim
99298845Sdim  if (nub.had_failure)
100298845Sdim    return svn_error_create(SVN_ERR_ILLEGAL_TARGET, NULL,
101298845Sdim                            _("One or more locks could not be released"));
102298845Sdim
103298845Sdim  return SVN_NO_ERROR;
104251881Speter}
105