2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-26 20:30:19 +00:00

Progress: Rename functions, fix documentation

This commit is contained in:
Alexander Neumann 2015-02-07 15:27:09 +01:00
parent 2b7af4a1c1
commit 57b8373bc9
2 changed files with 16 additions and 16 deletions

View File

@ -99,10 +99,10 @@ func (cmd CmdBackup) Execute(args []string) error {
scanProgress := restic.NewProgress(time.Second)
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))
}
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))
}
}
@ -145,7 +145,7 @@ func (cmd CmdBackup) Execute(args []string) error {
var bps, eta uint64
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)
if targetStat.Bytes > 0 && sec > 0 && ticker {
bps = s.Bytes / sec
@ -164,7 +164,7 @@ func (cmd CmdBackup) Execute(args []string) error {
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)
fmt.Printf("\nduration: %s, %.2fMiB/s\n",
format_duration(d),

View File

@ -7,9 +7,9 @@ import (
)
type Progress struct {
F ProgressFunc
D ProgressFunc
fnM sync.Mutex
OnUpdate ProgressFunc
OnDone ProgressFunc
fnM sync.Mutex
cur Stat
curM sync.Mutex
@ -31,9 +31,9 @@ type Stat struct {
type ProgressFunc func(s Stat, runtime time.Duration, ticker bool)
// 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
// interval. The function doneFn is called when Done() is called. Both
// functions F and D are called synchronously and can use shared state.
// the function OnUpdate is called when new data arrives or at least every d
// interval. The function OnDone is called when Done() is called. Both
// functions are called synchronously and can use shared state.
func NewProgress(d time.Duration) *Progress {
return &Progress{d: d}
}
@ -75,9 +75,9 @@ func (p *Progress) Report(s Stat) {
p.curM.Unlock()
// update progress
if p.F != nil {
if p.OnUpdate != nil {
p.fnM.Lock()
p.F(cur, time.Since(p.start), false)
p.OnUpdate(cur, time.Since(p.start), false)
p.fnM.Unlock()
}
}
@ -94,9 +94,9 @@ func (p *Progress) reporter() {
cur := p.cur
p.curM.Unlock()
if p.F != nil {
if p.OnUpdate != nil {
p.fnM.Lock()
p.F(cur, time.Since(p.start), true)
p.OnUpdate(cur, time.Since(p.start), true)
p.fnM.Unlock()
}
case <-p.cancel:
@ -139,9 +139,9 @@ func (p *Progress) Done() {
cur := p.cur
if p.D != nil {
if p.OnDone != nil {
p.fnM.Lock()
p.D(cur, time.Since(p.start), false)
p.OnDone(cur, time.Since(p.start), false)
p.fnM.Unlock()
}
}