forked from TrueCloudLab/restic
Progress: Rename functions, fix documentation
This commit is contained in:
parent
2b7af4a1c1
commit
57b8373bc9
2 changed files with 16 additions and 16 deletions
|
@ -99,10 +99,10 @@ func (cmd CmdBackup) Execute(args []string) error {
|
||||||
|
|
||||||
scanProgress := restic.NewProgress(time.Second)
|
scanProgress := restic.NewProgress(time.Second)
|
||||||
if terminal.IsTerminal(int(os.Stdout.Fd())) {
|
if terminal.IsTerminal(int(os.Stdout.Fd())) {
|
||||||
scanProgress.F = func(s restic.Stat, d time.Duration, ticker bool) {
|
scanProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||||
fmt.Printf("\x1b[2K\r[%s] %d directories, %d files, %s", format_duration(d), s.Dirs, s.Files, format_bytes(s.Bytes))
|
fmt.Printf("\x1b[2K\r[%s] %d directories, %d files, %s", format_duration(d), s.Dirs, s.Files, format_bytes(s.Bytes))
|
||||||
}
|
}
|
||||||
scanProgress.D = func(s restic.Stat, d time.Duration, ticker bool) {
|
scanProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||||
fmt.Printf("\nDone in %s\n", format_duration(d))
|
fmt.Printf("\nDone in %s\n", format_duration(d))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ func (cmd CmdBackup) Execute(args []string) error {
|
||||||
var bps, eta uint64
|
var bps, eta uint64
|
||||||
itemsTodo := targetStat.Files + targetStat.Dirs
|
itemsTodo := targetStat.Files + targetStat.Dirs
|
||||||
|
|
||||||
archiveProgress.F = func(s restic.Stat, d time.Duration, ticker bool) {
|
archiveProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||||
sec := uint64(d / time.Second)
|
sec := uint64(d / time.Second)
|
||||||
if targetStat.Bytes > 0 && sec > 0 && ticker {
|
if targetStat.Bytes > 0 && sec > 0 && ticker {
|
||||||
bps = s.Bytes / sec
|
bps = s.Bytes / sec
|
||||||
|
@ -164,7 +164,7 @@ func (cmd CmdBackup) Execute(args []string) error {
|
||||||
format_seconds(eta))
|
format_seconds(eta))
|
||||||
}
|
}
|
||||||
|
|
||||||
archiveProgress.D = func(s restic.Stat, d time.Duration, ticker bool) {
|
archiveProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||||
sec := uint64(d / time.Second)
|
sec := uint64(d / time.Second)
|
||||||
fmt.Printf("\nduration: %s, %.2fMiB/s\n",
|
fmt.Printf("\nduration: %s, %.2fMiB/s\n",
|
||||||
format_duration(d),
|
format_duration(d),
|
||||||
|
|
24
progress.go
24
progress.go
|
@ -7,9 +7,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Progress struct {
|
type Progress struct {
|
||||||
F ProgressFunc
|
OnUpdate ProgressFunc
|
||||||
D ProgressFunc
|
OnDone ProgressFunc
|
||||||
fnM sync.Mutex
|
fnM sync.Mutex
|
||||||
|
|
||||||
cur Stat
|
cur Stat
|
||||||
curM sync.Mutex
|
curM sync.Mutex
|
||||||
|
@ -31,9 +31,9 @@ type Stat struct {
|
||||||
type ProgressFunc func(s Stat, runtime time.Duration, ticker bool)
|
type ProgressFunc func(s Stat, runtime time.Duration, ticker bool)
|
||||||
|
|
||||||
// NewProgress returns a new progress reporter. After Start() has been called,
|
// NewProgress returns a new progress reporter. After Start() has been called,
|
||||||
// the function fn is called when new data arrives or at least every d
|
// the function OnUpdate is called when new data arrives or at least every d
|
||||||
// interval. The function doneFn is called when Done() is called. Both
|
// interval. The function OnDone is called when Done() is called. Both
|
||||||
// functions F and D are called synchronously and can use shared state.
|
// functions are called synchronously and can use shared state.
|
||||||
func NewProgress(d time.Duration) *Progress {
|
func NewProgress(d time.Duration) *Progress {
|
||||||
return &Progress{d: d}
|
return &Progress{d: d}
|
||||||
}
|
}
|
||||||
|
@ -75,9 +75,9 @@ func (p *Progress) Report(s Stat) {
|
||||||
p.curM.Unlock()
|
p.curM.Unlock()
|
||||||
|
|
||||||
// update progress
|
// update progress
|
||||||
if p.F != nil {
|
if p.OnUpdate != nil {
|
||||||
p.fnM.Lock()
|
p.fnM.Lock()
|
||||||
p.F(cur, time.Since(p.start), false)
|
p.OnUpdate(cur, time.Since(p.start), false)
|
||||||
p.fnM.Unlock()
|
p.fnM.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,9 +94,9 @@ func (p *Progress) reporter() {
|
||||||
cur := p.cur
|
cur := p.cur
|
||||||
p.curM.Unlock()
|
p.curM.Unlock()
|
||||||
|
|
||||||
if p.F != nil {
|
if p.OnUpdate != nil {
|
||||||
p.fnM.Lock()
|
p.fnM.Lock()
|
||||||
p.F(cur, time.Since(p.start), true)
|
p.OnUpdate(cur, time.Since(p.start), true)
|
||||||
p.fnM.Unlock()
|
p.fnM.Unlock()
|
||||||
}
|
}
|
||||||
case <-p.cancel:
|
case <-p.cancel:
|
||||||
|
@ -139,9 +139,9 @@ func (p *Progress) Done() {
|
||||||
|
|
||||||
cur := p.cur
|
cur := p.cur
|
||||||
|
|
||||||
if p.D != nil {
|
if p.OnDone != nil {
|
||||||
p.fnM.Lock()
|
p.fnM.Lock()
|
||||||
p.D(cur, time.Since(p.start), false)
|
p.OnDone(cur, time.Since(p.start), false)
|
||||||
p.fnM.Unlock()
|
p.fnM.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue