13 #include <string_view>
15 #include <fmt/format.h>
23 static constexpr std::array<std::string_view, 4> RSYNC_UNITS = {
"B/s",
"kB/s",
"MB/s",
"GB/s"};
25 static std::vector<std::string>
26 MakeAsyncProcessArgs(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(
"--dry-run");
48 args.emplace_back(
"--times");
50 args.emplace_back(
"--info=progress2");
52 args.emplace_back(
"--no-human-readable");
53 args.emplace_back(std::move(source));
54 args.emplace_back(std::move(dest));
61 using std::chrono::hours;
62 using std::chrono::minutes;
63 using std::chrono::seconds;
78 auto ret = std::sscanf(line.c_str(),
79 " %lu %u%% %f%4s %u:%u:%u",
90 progress.
progress = percent / 100.0f;
92 for (
auto u : RSYNC_UNITS) {
102 progress.
speed = speed;
103 progress.
remaining = hours(hrs) + minutes(mins) + seconds(secs);
112 :
AsyncProcess(ctx, MakeAsyncProcessArgs(std::move(source), std::move(dest), opts, flag)) {
122 if (maybe_progress) {
123 m_progress(pid, *maybe_progress);
130 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.