«
Previous
|
Next
»
Revision dbbd2afa
Added by david.sorber over 2 years ago
- ID dbbd2afaf6410ef19291da7d0d18b16407571023
- Parent 4fd46efa
| src/copytool_main.cc | ||
|---|---|---|
|
const std::string UP_ONE = "\033[1A";
|
||
|
|
||
|
|
||
|
int main(int argc, char** argv)
|
||
|
{
|
||
|
int main(int argc, char** argv) {
|
||
|
std::cout << "copytool -- " << VERSION << "\n" << std::endl;
|
||
|
CLI::App app{"copytool"};
|
||
|
|
||
| ... | ... | |
|
app.add_option("-l,--log-file-path", logFilePath, "log file path");
|
||
|
app.add_option("--log-level", logLevel,
|
||
|
"default log message level (error=0, warn=1, info=2, debug=3, trace=4)")
|
||
|
->check(CLI::Range(0, 4));
|
||
|
->check(CLI::Range(0, 4));
|
||
|
|
||
|
// Other options
|
||
|
uint32_t flowControlThreshold = DBS::CopyManagerOptions::DEFAULT_FC_THRESHOLD;
|
||
|
uint32_t numCopyThreads = DBS::CopyManagerOptions::DEFAULT_NUM_COPY_THREADS;
|
||
|
bool copyTopLevel = DBS::CopyManagerOptions::DEFAULT_COPY_TOPLEVEL;
|
||
|
bool preservePerms = DBS::CopyManagerOptions::DEFAULT_PRESERVE_PERMS;
|
||
|
bool preserveOwner = DBS::CopyManagerOptions::DEFAULT_PRESERVE_OWNER;
|
||
|
bool preserveGroup = DBS::CopyManagerOptions::DEFAULT_PRESERVE_GROUP;
|
||
|
|
||
|
app.add_option("--flow-control-threshold", flowControlThreshold,
|
||
|
"flow control threshold (default: "
|
||
|
+ std::to_string(flowControlThreshold) + ")")
|
||
|
->check(CLI::Range(100,65535));
|
||
|
->check(CLI::Range(100, 65535));
|
||
|
app.add_option("-n,--num-copy-threads", numCopyThreads,
|
||
|
"number of copy threads to spawn (default: "
|
||
|
+ std::to_string(numCopyThreads) + ")")
|
||
|
->check(CLI::Range(1, 512));
|
||
|
->check(CLI::Range(1, 512));
|
||
|
app.add_flag("--copy-top-level", copyTopLevel,
|
||
|
"copy top level source directory to destination rather then "
|
||
|
"the contents of the top level source directory (which is "
|
||
|
"the default behavior)");
|
||
|
|
||
|
app.add_flag("-p,--preserve-perms", preservePerms,
|
||
|
"preserve file/directory permissions");
|
||
|
app.add_flag("-o,--preserve-owner", preserveOwner,
|
||
|
"preserve file/directory owner");
|
||
|
app.add_flag("-g,--preserve-group", preserveGroup,
|
||
|
"preserve file/directory group");
|
||
|
|
||
|
|
||
|
// Parse options
|
||
|
CLI11_PARSE(app, argc, argv);
|
||
|
|
||
| ... | ... | |
|
logLevel,
|
||
|
flowControlThreshold,
|
||
|
numCopyThreads,
|
||
|
copyTopLevel);
|
||
|
copyTopLevel,
|
||
|
preservePerms,
|
||
|
preserveOwner,
|
||
|
preserveGroup);
|
||
|
|
||
|
// Prime the logger
|
||
|
DBS::Logger::getInstance(DBS::off, &options);
|
||
|
try
|
||
|
{
|
||
|
DBS::Logger::getInstance(DBS::off, &options);
|
||
|
}
|
||
|
catch (const std::runtime_error& excep)
|
||
|
{
|
||
|
std::cerr << BOLD << RED << "ERROR: " << ENDC << excep.what()
|
||
|
<< "\n" << std::endl;
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
LOG(DBS::info) << "copytool -- DBS";
|
||
|
|
||
|
// Display a warning if the specified number of copy threads exceeds the
|
||
| ... | ... | |
|
|
||
|
int rc = manager.waitForComplete();
|
||
|
|
||
|
pBarEta.set_progress(100.0);
|
||
|
pBarEta.set_option(indicators::option::PostfixText{" -- " +
|
||
|
std::to_string(manager.getProcessedEntries()) + "/" +
|
||
|
std::to_string(manager.getTotalEntries())
|
||
|
});
|
||
|
pBarEta.mark_as_completed();
|
||
|
indicators::show_console_cursor(true);
|
||
|
std::cout << std::endl;
|
||
|
if (manager.iterationError())
|
||
|
{
|
||
|
std::cerr << BOLD << RED << "ERROR: " << ENDC << "An iteration exception "
|
||
|
<< "occurred that was likely caused by a permissions error. "
|
||
|
<< "Please rerun as root (using sudo)." << std::endl;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
pBarEta.set_progress(100.0);
|
||
|
pBarEta.set_option(indicators::option::PostfixText{" -- " +
|
||
|
std::to_string(manager.getProcessedEntries()) + "/" +
|
||
|
std::to_string(manager.getTotalEntries())
|
||
|
});
|
||
|
pBarEta.mark_as_completed();
|
||
|
indicators::show_console_cursor(true);
|
||
|
std::cout << std::endl;
|
||
|
}
|
||
|
|
||
|
// Display warning to user if any invalid/unsupported directory entries were
|
||
|
// found while copying
|
||
| ... | ... | |
|
{
|
||
|
std::cout << BOLD << YELLOW << "WARNING: " << ENDC
|
||
|
<< manager.getInvalidEntries() << " unsupported directory "
|
||
|
<< "entries (symlinks, FIFOs, etc.) were NOT copied.\n"
|
||
|
<< "entries (symlinks, FIFOs, etc.) were NOT copied."
|
||
|
<< std::endl;
|
||
|
}
|
||
|
|
||
|
std::cout << std::endl;
|
||
|
|
||
|
return rc;
|
||
|
}
|
||
WIP; adding options to preserve file/directory permissions, owner, and
group.