From 57b8373bc900701de386a7a4329ee4fb7664f055 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 7 Feb 2015 15:27:09 +0100 Subject: [PATCH] Progress: Rename functions, fix documentation --- cmd/restic/cmd_backup.go | 8 ++++---- progress.go | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 1259050e5..f128f487d 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -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), diff --git a/progress.go b/progress.go index 086b06a5c..b33c0d9aa 100644 --- a/progress.go +++ b/progress.go @@ -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() } }