| 1 |
/* |
| 2 |
* This File is part of Davix, The IO library for HTTP based protocols |
| 3 |
* Copyright (C) CERN 2013 |
| 4 |
* Author: Adrien Devresse <[email protected]> |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 2.1 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <davix.hpp> |
| 23 |
#include <tools/davix_tool_params.hpp> |
| 24 |
#include <tools/davix_tool_util.hpp> |
| 25 |
|
| 26 |
|
| 27 |
using namespace Davix; |
| 28 |
using namespace std; |
| 29 |
|
| 30 |
|
| 31 |
const std::string scope_main = "Davix::Tools::davix"; |
| 32 |
|
| 33 |
std::string get_base_copy_options(){ |
| 34 |
return " Copy Options:\n" |
| 35 |
"\t--copy-mode: 3rd party copy mode - push(default) or pull\n"; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
static void performanceCallback(const PerformanceData& perfData, void *udata) |
| 40 |
{ |
| 41 |
(void) udata; |
| 42 |
std::cout << perfData.totalTransferred() |
| 43 |
<< " (" << perfData.avgTransfer() << " bytes/sec)" |
| 44 |
<< std::endl; |
| 45 |
} |
| 46 |
|
| 47 |
static std::string help_msg(const std::string & cmd_path){ |
| 48 |
std::string help_str = fmt::format("Usage : {} ", cmd_path); |
| 49 |
help_str += Tool::get_copy_description_options(); |
| 50 |
help_str += get_base_copy_options(); |
| 51 |
help_str += Tool::get_common_options(); |
| 52 |
|
| 53 |
return help_str; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
int main(int argc, char** argv) { |
| 58 |
DavixError* tmp_err = NULL; |
| 59 |
Tool::OptParams opts; |
| 60 |
int retcode; |
| 61 |
|
| 62 |
opts.help_msg = help_msg(argv[0]); |
| 63 |
|
| 64 |
if ((retcode = parse_davix_copy_options(argc, argv, opts, &tmp_err)) == 0) { |
| 65 |
if (opts.vec_arg.size() != 2) { |
| 66 |
DavixError::setupError(&tmp_err, scope_main, StatusCode::InvalidArgument, "Copy command must contain exactly one <src> and <dst> URL!"); |
| 67 |
} |
| 68 |
|
| 69 |
if (!tmp_err) { |
| 70 |
Uri src(opts.vec_arg[0]); |
| 71 |
|
| 72 |
if (src.getStatus() != StatusCode::OK) { |
| 73 |
DavixError::setupError(&tmp_err, scope_main, src.getStatus(), "Source \"" + opts.vec_arg[0] + "\" not a valid URL!"); |
| 74 |
} else { |
| 75 |
Uri dst(opts.vec_arg[1]); |
| 76 |
|
| 77 |
if (dst.getStatus() != StatusCode::OK) { |
| 78 |
DavixError::setupError(&tmp_err, scope_main, dst.getStatus(), "Destination \"" + opts.vec_arg[1] + "\" not a valid URL!"); |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
if (!tmp_err && (retcode = configureAuth(opts)) == 0) { |
| 84 |
Context c; |
| 85 |
configureContext(c, opts); |
| 86 |
DavixCopy copy(c, &opts.params); |
| 87 |
copy.setPerformanceCallback(performanceCallback, NULL); |
| 88 |
copy.copy(opts.vec_arg[0], opts.vec_arg[1], 1, &tmp_err); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
if (tmp_err) { |
| 93 |
retcode = -1; |
| 94 |
} |
| 95 |
|
| 96 |
Tool::errorPrint(&tmp_err); |
| 97 |
return retcode; |
| 98 |
} |