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>
23
24using namespace application;
25using namespace basis;
26using namespace filesystem;
27using namespace loggers;
28using namespace octopi;
29using namespace structures;
30using namespace textual;
31using 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
38class synch_files_tentacle : public application_shell
39{
40public:
41 synch_files_tentacle() : application_shell() {}
42 DEFINE_CLASS_NAME("test_dirtree_fcopy");
43 int execute();
44};
45
46int synch_files_tentacle::execute()
47{
48 FUNCDEF("execute");
49
50 if (_global_argc < 3) {
51 log(astring("\
52This program needs two parameters:\n\
53a directory for the source root and one for the target root.\n\
54Optionally, a third parameter may specify a starting point within the\n\
55source root.\n\
56Further, if fourth or more parameters are found, they are taken to be\n\
57files 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!
79 target_dir, includes, source_start);
80
81 if (returned != common::OKAY) {
82 critical_events::alert_message(astring("copy failure with outcome=")
84 return 1;
85 } else return 0;
86}
87
88HOOPLE_MAIN(synch_files_tentacle, )
89
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
application_shell()
constructs an application_shell to serve as the root of the program.
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
Outcomes describe the state of completion for an operation.
Definition outcome.h:31
static void alert_message(const char *info, const char *title="Alert Message")
shows the message in "info", with an optional "title" on the message.
@ COMPARE_SIZE_AND_TIME
uses size and time to see differences.
static const char * outcome_name(const basis::outcome &to_name)
static basis::outcome copy_hierarchy(int transfer_mode, const basis::astring &source_dir, const basis::astring &target_dir, const structures::string_array &includes, const basis::astring &source_start=basis::astring::empty_string())
copies a directory hierarchy starting at "source_dir" into "target_dir".
An array of strings with some additional helpful methods.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition enhance_cpp.h:42
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition enhance_cpp.h:54
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.
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>