2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

ui/progress: don't print progress on non-interactive terminals

This reverts to the old behavior of not printing progress updates on
non-interactive terminals. It was accidentally changed in #3058.
This commit is contained in:
Michael Eischer 2020-12-28 23:11:42 +01:00
parent a488d4c847
commit c2ef049f1b
4 changed files with 37 additions and 11 deletions

View File

@ -17,7 +17,7 @@ func newProgressMax(show bool, max uint64, description string) *progress.Counter
interval := time.Second / 60 interval := time.Second / 60
if !stdoutIsTerminal() { if !stdoutIsTerminal() {
interval = time.Second interval = 0
} else { } else {
fps, err := strconv.ParseInt(os.Getenv("RESTIC_PROGRESS_FPS"), 10, 64) fps, err := strconv.ParseInt(os.Getenv("RESTIC_PROGRESS_FPS"), 10, 64)
if err == nil && fps >= 1 { if err == nil && fps >= 1 {

View File

@ -133,15 +133,14 @@ command:
--tls-client-cert file path to a file containing PEM encoded TLS client certificate and private key --tls-client-cert file path to a file containing PEM encoded TLS client certificate and private key
-v, --verbose n be verbose (specify multiple times or a level using --verbose=n, max level/times is 3) -v, --verbose n be verbose (specify multiple times or a level using --verbose=n, max level/times is 3)
Subcommand that support showing progress information such as ``backup``, Subcommands that support showing progress information such as ``backup``,
``check`` and ``prune`` will do so unless the quiet flag ``-q`` or ``check`` and ``prune`` will do so unless the quiet flag ``-q`` or
``--quiet`` is set. When running from a non-interactive console progress ``--quiet`` is set. For interactive consoles the environment variable
reporting will be limited to once every 10 seconds to not fill your ``RESTIC_PROGRESS_FPS`` can be used to control the frequency of progress
logs. Use ``backup`` with the quiet flag ``-q`` or ``--quiet`` to skip reporting. When running from a non-interactive console progress reporting
the initial scan of the source directory, this may shorten the backup is disabled to not fill your logs.
time needed for large directories.
Additionally on Unix systems if ``restic`` receives a SIGUSR1 signal the Additionally, on Unix systems if ``restic`` receives a SIGUSR1 signal the
current progress will be written to the standard output so you can check up current progress will be written to the standard output so you can check up
on the status at will. on the status at will.

View File

@ -41,7 +41,9 @@ func New(interval time.Duration, report Func) *Counter {
start: time.Now(), start: time.Now(),
stopped: make(chan struct{}), stopped: make(chan struct{}),
stop: make(chan struct{}), stop: make(chan struct{}),
tick: time.NewTicker(interval), }
if interval > 0 {
c.tick = time.NewTicker(interval)
} }
go c.run() go c.run()
@ -64,7 +66,9 @@ func (c *Counter) Done() {
if c == nil { if c == nil {
return return
} }
if c.tick != nil {
c.tick.Stop() c.tick.Stop()
}
close(c.stop) close(c.stop)
<-c.stopped // Wait for last progress report. <-c.stopped // Wait for last progress report.
*c = Counter{} // Prevent reuse. *c = Counter{} // Prevent reuse.
@ -85,11 +89,15 @@ func (c *Counter) run() {
c.report(c.get(), time.Since(c.start), true) c.report(c.get(), time.Since(c.start), true)
}() }()
var tick <-chan time.Time
if c.tick != nil {
tick = c.tick.C
}
for { for {
var now time.Time var now time.Time
select { select {
case now = <-c.tick.C: case now = <-tick:
case sig := <-signals.ch: case sig := <-signals.ch:
debug.Log("Signal received: %v\n", sig) debug.Log("Signal received: %v\n", sig)
now = time.Now() now = time.Now()

View File

@ -53,3 +53,22 @@ func TestCounterNil(t *testing.T) {
c.Add(1) c.Add(1)
c.Done() c.Done()
} }
func TestCounterNoTick(t *testing.T) {
finalSeen := false
otherSeen := false
report := func(value uint64, d time.Duration, final bool) {
if final {
finalSeen = true
} else {
otherSeen = true
}
}
c := progress.New(0, report)
time.Sleep(time.Millisecond)
c.Done()
test.Assert(t, finalSeen, "final call did not happen")
test.Assert(t, !otherSeen, "unexpected status update")
}