copy: calculate bytes per second while copying, and pass to progress info
Also, show it in import-fs/repart.
This commit is contained in:
committed by
Luca Boccassi
parent
e566236fc1
commit
acd4943528
+13
-2
@@ -26,12 +26,13 @@
|
||||
#include "path-util.h"
|
||||
#include "rm-rf.h"
|
||||
#include "selinux-util.h"
|
||||
#include "set.h"
|
||||
#include "signal-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "set.h"
|
||||
#include "stdio-util.h"
|
||||
#include "string-util.h"
|
||||
#include "sync-util.h"
|
||||
#include "time-util.h"
|
||||
#include "tmpfile-util.h"
|
||||
#include "umask-util.h"
|
||||
#include "user-util.h"
|
||||
@@ -263,6 +264,10 @@ int copy_bytes_full(
|
||||
}
|
||||
}
|
||||
|
||||
usec_t start_timestamp = USEC_INFINITY;
|
||||
if (progress)
|
||||
start_timestamp = now(CLOCK_MONOTONIC);
|
||||
|
||||
for (;;) {
|
||||
ssize_t n;
|
||||
size_t m;
|
||||
@@ -511,7 +516,13 @@ int copy_bytes_full(
|
||||
try_sendfile = false;
|
||||
|
||||
if (progress) {
|
||||
r = progress(n, userdata);
|
||||
usec_t t = now(CLOCK_MONOTONIC);
|
||||
usec_t d = usec_sub_unsigned(t, start_timestamp);
|
||||
uint64_t bps = UINT64_MAX;
|
||||
if (d > USEC_PER_SEC * 3U)
|
||||
bps = (uint64_t) (copied_total / ((double) d / USEC_PER_SEC));
|
||||
|
||||
r = progress(n, bps, userdata);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ typedef enum DenyType {
|
||||
_DENY_TYPE_INVALID = -EINVAL,
|
||||
} DenyType;
|
||||
|
||||
typedef int (*copy_progress_bytes_t)(uint64_t n_bytes, void *userdata);
|
||||
typedef int (*copy_progress_bytes_t)(uint64_t n_bytes, uint64_t bytes_per_second, void *userdata);
|
||||
typedef int (*copy_progress_path_t)(const char *path, const struct stat *st, void *userdata);
|
||||
|
||||
int copy_file_fd_at_full(int dir_fdf, const char *from, int to, CopyFlags copy_flags, copy_progress_bytes_t progress, void *userdata);
|
||||
|
||||
Reference in New Issue
Block a user