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);