using global rate gives wildly inacurrate ETAs if rate changes over time.
this makes pv keep a history of progress over the last 30s interval and compute
current average rate over that, which fixes the issue.
fixed -a, --average-rate: show current average rate instead of global rate
[ quick test ]
- in one shell:
$ dd if=/dev/zero of=/tmp/foo bs=1M count=5 # simulate fast initial rate,
$ (while true; do ls /*; sleep 1; done) >> /tmp/foo # then slow rate. leave running ...
- in another shell:
$ tail -f -n +1 /tmp/foo | pv -s 800M > /dev/null
5.62MiB 0:00:17 [33.1KiB/s] [> ] 0% ETA 0:40:02
bad: (pv 1.6.6 - 1.6.20)
ETA of a few minutes that keeps increasing ever and ever ...
5.62MiB 0:00:16 [33.1KiB/s] [> ] 0% ETA 6:45:53
good:
ETA of 6+ hours, which is how long it'll take to reach 800Mb at 33k/s
Show pv progress bar even if no terminal is set, e.g., in a busybox
init script. The description of pv_in_forground() states it will
return true "if we aren't outputting to a terminal". However, this
is not the case since tcgetpgrg() will return an error and set ERRNO
to ENOTTY if the output fd is not an tty. We now handle this error
correctly and pv_in_foreground() returns also true in that case.
Signed-off-by: Michael Weiß <michael.weiss@aisec.fraunhofer.de>