feisty meow concerns codebase  2.140
synch_files.cpp
Go to the documentation of this file.
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 
16 #include <basis/functions.h>
17 #include <loggers/console_logger.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 #define DEBUG_SYNCH_FILES
36 //hmmm: not used yet, but should be.
37 
38 class synch_files_tentacle : public application_shell
39 {
40 public:
41  synch_files_tentacle() : application_shell() {}
42  DEFINE_CLASS_NAME("test_dirtree_fcopy");
43  int execute();
44 };
45 
46 int synch_files_tentacle::execute()
47 {
48  FUNCDEF("execute");
49 
50  if (_global_argc < 3) {
51  log(astring("\
52 This program needs two parameters:\n\
53 a directory for the source root and one for the target root.\n\
54 Optionally, a third parameter may specify a starting point within the\n\
55 source root.\n\
56 Further, if fourth or more parameters are found, they are taken to be\n\
57 files to include; only they will be transferred.\n"), ALWAYS_PRINT);
58  return 23;
59  }
60 
61  astring source_dir = _global_argv[1];
62  astring target_dir = _global_argv[2];
63 
64  astring source_start = "";
65  if (_global_argc >= 4) {
66  source_start = _global_argv[3];
67  }
68 
69  string_array includes;
70  if (_global_argc >= 5) {
71  for (int i = 4; i < _global_argc; i++) {
72  includes += _global_argv[i];
73  }
74  }
75 
76 //hmmm: make comparing the file chunks an option too!
77  outcome returned = recursive_file_copy::copy_hierarchy
78  (file_transfer_tentacle::COMPARE_SIZE_AND_TIME, source_dir,
79  target_dir, includes, source_start);
80 
81  if (returned != common::OKAY) {
82  critical_events::alert_message(astring("copy failure with outcome=")
83  + recursive_file_copy::outcome_name(returned));
84  return 1;
85  } else return 0;
86 }
87 
88 HOOPLE_MAIN(synch_files_tentacle, )
89 
The application_shell is a base object for console programs.
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
An array of strings with some additional helpful methods.
Definition: string_array.h:32
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition: enhance_cpp.h:45
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition: enhance_cpp.h:57
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition: hoople_main.h:61
Implements an application lock to ensure only one is running at once.
char ** _global_argv
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55
#include <time.h>
Definition: earth_time.cpp:37