2c42466363df4b82a8307a1cc1d58753afdf8814
[feisty_meow.git] / octopi / applications / transporter / synch_files.cpp
1 /*
2 *  Name   : synch_files
3 *  Author : Chris Koeritz
4 *  Purpose:                                                                   *
5 *    Provides a file transfer utility using the file_transfer_tentacle.       *
6 *******************************************************************************
7 * Copyright (c) 2005-$now By Author.  This program is free software; you can  *
8 * redistribute it and/or modify it under the terms of the GNU General Public  *
9 * License as published by the Free Software Foundation; either version 2 of   *
10 * the License or (at your option) any later version.  This is online at:      *
11 *     http://www.fsf.org/copyleft/gpl.html                                    *
12 * Please send any updates to: fred@gruntose.com
13 */
14
15 #include <application/hoople_main.h>
16 #include <basis/functions.h>
17 #include <loggers/console_logger.h>
18 #include <loggers/critical_events.h>
19 #include <structures/static_memory_gremlin.h>
20 #include <structures/string_array.h>
21 #include <tentacles/file_transfer_tentacle.h>
22 #include <tentacles/recursive_file_copy.h>
23
24 using namespace application;
25 using namespace basis;
26 using namespace filesystem;
27 using namespace loggers;
28 using namespace octopi;
29 using namespace structures;
30 using namespace textual;
31 using namespace timely;
32
33 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
34
35 class synch_files_tentacle : public application_shell
36 {
37 public:
38   synch_files_tentacle() : application_shell() {}
39   DEFINE_CLASS_NAME("test_dirtree_fcopy");
40   int execute();
41 };
42
43 int synch_files_tentacle::execute()
44 {
45   FUNCDEF("execute");
46
47   if (_global_argc < 3) {
48     log(astring("\
49 This program needs two parameters:\n\
50 a directory for the source root and one for the target root.\n\
51 Optionally, a third parameter may specify a starting point within the\n\
52 source root.\n\
53 Further, if fourth or more parameters are found, they are taken to be\n\
54 files to include; only they will be transferred.\n"), ALWAYS_PRINT);
55     return 23;
56   }
57
58   astring source_dir = _global_argv[1];
59   astring target_dir = _global_argv[2];
60
61   astring source_start = "";
62   if (_global_argc >= 4) {
63     source_start = _global_argv[3];
64   }
65
66   string_array includes;
67   if (_global_argc >= 5) {
68     for (int i = 4; i < _global_argc; i++) {
69       includes += _global_argv[i];
70     }
71   }
72
73 //hmmm: make comparing the file chunks an option too!
74   outcome returned = recursive_file_copy::copy_hierarchy
75       (file_transfer_tentacle::COMPARE_SIZE_AND_TIME, source_dir,
76       target_dir, includes, source_start);
77
78   if (returned != common::OKAY) {
79     critical_events::alert_message(astring("copy failure with outcome=")
80         + recursive_file_copy::outcome_name(returned));
81     return 1;
82   } else return 0;
83 }
84
85 HOOPLE_MAIN(synch_files_tentacle, )
86