15#include <fmt/format.h>
23static constexpr std::array<std::string_view, 4> RSYNC_UNITS = {
"B/s",
"kB/s",
"MB/s",
"GB/s"};
25static std::vector<std::string>
26MakeAsyncProcessArgs(std::string source,
28 RsyncOptions
const& opts,
30 std::vector<std::string> args;
31 args.emplace_back(opts.rsync.value_or(
"rsync"));
33 args.emplace_back(fmt::format(
"--bwlimit={}", *opts.bw_limit));
35 if (opts.whole_file) {
36 args.emplace_back(*opts.whole_file ?
"--whole-file" :
"--no-whole-file");
39 args.emplace_back(*opts.whole_file ?
"--inplace" :
"--no-inplace");
42 args.emplace_back(fmt::format(
"--timeout={}", opts.timeout->count()));
45 args.emplace_back(fmt::format(
"--log-file={}", opts.logfile->native()));
48 args.emplace_back(
"--dry-run");
51 args.emplace_back(
"--times");
53 args.emplace_back(
"--info=progress2");
55 args.emplace_back(
"--no-human-readable");
56 args.emplace_back(std::move(source));
57 args.emplace_back(std::move(dest));
64 using std::chrono::hours;
65 using std::chrono::minutes;
66 using std::chrono::seconds;
81 auto ret = std::sscanf(line.c_str(),
82 " %lu %u%% %f%4s %u:%u:%u",
93 progress.
progress = percent / 100.0f;
95 for (
auto u : RSYNC_UNITS) {
105 progress.
speed = speed;
106 progress.
remaining = hours(hrs) + minutes(mins) + seconds(secs);
115 :
AsyncProcess(ctx, MakeAsyncProcessArgs(std::move(source), std::move(dest), opts, flag)) {
125 if (maybe_progress) {
126 m_progress(pid, *maybe_progress);
133 return m_progress.connect(slot);
Represents a subprocess as an asynchronous operation.
boost::future< int > Initiate() override
Starts process and asynchronous operations that read stdout and stderr.
boost::signals2::connection ConnectStdout(SigOutStream::slot_type const &slot) override
Signal type for stdout/stderr signals.
boost::future< int > Initiate() override
Progress update signal.
RsyncAsyncProcess(boost::asio::io_context &ctx, std::string source, std::string dest, RsyncOptions const &opts={}, DryRun flag=DryRun::Disabled)
Construct async operation.
virtual ~RsyncAsyncProcess()
boost::signals2::connection ConnectProgress(SigProgress::slot_type const &slot) override
Connect to progress signal.
std::chrono::seconds remaining
Estimated remaining time.
std::optional< RsyncProgress > ParseRsyncProgress(std::string const &line) noexcept
Parse progress update from rsync.
float progress
Progress as fraction of 1 (complete == 1.0)
uint64_t transferred
Number of transferred bytes.
float speed
Transfer speed in bytes/sec.
Options controlling rsync invocation.
Describes file transfer progress,.
daq::RsyncAsyncProcess and related class declarations.