mirror of https://github.com/restic/restic.git
Merge pull request #974 from restic/remove-noninteractive-progress
Remove regular status printing for non terminals
This commit is contained in:
commit
e73e3cb4ba
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -1,6 +1,17 @@
|
|||
This file describes changes relevant to all users that are made in each
|
||||
released version of restic from the perspective of the user.
|
||||
|
||||
Important Changes in 0.X.Y
|
||||
==========================
|
||||
|
||||
Small changes:
|
||||
--------------
|
||||
|
||||
* Regular status report: We've removed the status report that was printed
|
||||
every 10 seconds when restic is run non-interactively. You can still force
|
||||
reporting the current status by sending a `USR1` signal to the process.
|
||||
https://github.com/restic/restic/pull/974
|
||||
|
||||
Important Changes in 0.6.0
|
||||
==========================
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ const minTickerTime = time.Second / 60
|
|||
var isTerminal = terminal.IsTerminal(int(os.Stdout.Fd()))
|
||||
var forceUpdateProgress = make(chan bool)
|
||||
|
||||
// Progress reports progress on an operation.
|
||||
type Progress struct {
|
||||
OnStart func()
|
||||
OnUpdate ProgressFunc
|
||||
|
@ -32,6 +33,7 @@ type Progress struct {
|
|||
running bool
|
||||
}
|
||||
|
||||
// Stat captures newly done parts of the operation.
|
||||
type Stat struct {
|
||||
Files uint64
|
||||
Dirs uint64
|
||||
|
@ -41,6 +43,7 @@ type Stat struct {
|
|||
Errors uint64
|
||||
}
|
||||
|
||||
// ProgressFunc is used to report progress back to the user.
|
||||
type ProgressFunc func(s Stat, runtime time.Duration, ticker bool)
|
||||
|
||||
// NewProgress returns a new progress reporter. When Start() is called, the
|
||||
|
@ -50,10 +53,7 @@ type ProgressFunc func(s Stat, runtime time.Duration, ticker bool)
|
|||
// synchronously and can use shared state.
|
||||
func NewProgress() *Progress {
|
||||
var d time.Duration
|
||||
if !isTerminal {
|
||||
// TODO: make the duration for non-terminal progress (user) configurable
|
||||
d = time.Duration(10) * time.Second
|
||||
} else {
|
||||
if isTerminal {
|
||||
d = time.Second
|
||||
}
|
||||
return &Progress{d: d}
|
||||
|
@ -70,7 +70,10 @@ func (p *Progress) Start() {
|
|||
p.running = true
|
||||
p.Reset()
|
||||
p.start = time.Now()
|
||||
p.c = nil
|
||||
if p.d != 0 {
|
||||
p.c = time.NewTicker(p.d)
|
||||
}
|
||||
|
||||
if p.OnStart != nil {
|
||||
p.OnStart()
|
||||
|
@ -143,14 +146,21 @@ func (p *Progress) reporter() {
|
|||
p.updateProgress(cur, true)
|
||||
}
|
||||
|
||||
var ticker <-chan time.Time
|
||||
if p.c != nil {
|
||||
ticker = p.c.C
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-p.c.C:
|
||||
case <-ticker:
|
||||
updateProgress()
|
||||
case <-forceUpdateProgress:
|
||||
updateProgress()
|
||||
case <-p.cancel:
|
||||
if p.c != nil {
|
||||
p.c.Stop()
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue