mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 02:48: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:
parent
a488d4c847
commit
c2ef049f1b
@ -17,7 +17,7 @@ func newProgressMax(show bool, max uint64, description string) *progress.Counter
|
||||
|
||||
interval := time.Second / 60
|
||||
if !stdoutIsTerminal() {
|
||||
interval = time.Second
|
||||
interval = 0
|
||||
} else {
|
||||
fps, err := strconv.ParseInt(os.Getenv("RESTIC_PROGRESS_FPS"), 10, 64)
|
||||
if err == nil && fps >= 1 {
|
||||
|
@ -133,15 +133,14 @@ command:
|
||||
--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)
|
||||
|
||||
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
|
||||
``--quiet`` is set. When running from a non-interactive console progress
|
||||
reporting will be limited to once every 10 seconds to not fill your
|
||||
logs. Use ``backup`` with the quiet flag ``-q`` or ``--quiet`` to skip
|
||||
the initial scan of the source directory, this may shorten the backup
|
||||
time needed for large directories.
|
||||
``--quiet`` is set. For interactive consoles the environment variable
|
||||
``RESTIC_PROGRESS_FPS`` can be used to control the frequency of progress
|
||||
reporting. When running from a non-interactive console progress reporting
|
||||
is disabled to not fill your logs.
|
||||
|
||||
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
|
||||
on the status at will.
|
||||
|
||||
|
@ -41,7 +41,9 @@ func New(interval time.Duration, report Func) *Counter {
|
||||
start: time.Now(),
|
||||
stopped: make(chan struct{}),
|
||||
stop: make(chan struct{}),
|
||||
tick: time.NewTicker(interval),
|
||||
}
|
||||
if interval > 0 {
|
||||
c.tick = time.NewTicker(interval)
|
||||
}
|
||||
|
||||
go c.run()
|
||||
@ -64,7 +66,9 @@ func (c *Counter) Done() {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
c.tick.Stop()
|
||||
if c.tick != nil {
|
||||
c.tick.Stop()
|
||||
}
|
||||
close(c.stop)
|
||||
<-c.stopped // Wait for last progress report.
|
||||
*c = Counter{} // Prevent reuse.
|
||||
@ -85,11 +89,15 @@ func (c *Counter) run() {
|
||||
c.report(c.get(), time.Since(c.start), true)
|
||||
}()
|
||||
|
||||
var tick <-chan time.Time
|
||||
if c.tick != nil {
|
||||
tick = c.tick.C
|
||||
}
|
||||
for {
|
||||
var now time.Time
|
||||
|
||||
select {
|
||||
case now = <-c.tick.C:
|
||||
case now = <-tick:
|
||||
case sig := <-signals.ch:
|
||||
debug.Log("Signal received: %v\n", sig)
|
||||
now = time.Now()
|
||||
|
@ -53,3 +53,22 @@ func TestCounterNil(t *testing.T) {
|
||||
c.Add(1)
|
||||
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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user