lib/scanner: Don't stop byte counter ticks before scan is done

This commit is contained in:
Jakob Borg 2017-01-03 15:03:18 +01:00
parent 79dd6918f2
commit 2ebd6ad77f
2 changed files with 4 additions and 3 deletions

View File

@ -154,7 +154,7 @@ func (s *verboseService) formatEvent(ev events.Event) string {
if total > 0 {
pct = 100 * current / total
}
return fmt.Sprintf("Scanning folder %q, %d%% done (%.01f MB/s)", folder, pct, rate)
return fmt.Sprintf("Scanning folder %q, %d%% done (%.01f MiB/s)", folder, pct, rate)
case events.DevicePaused:
data := ev.Data.(map[string]string)

View File

@ -169,13 +169,14 @@ func (w *walker) walk() (chan protocol.FileInfo, error) {
realToHashChan := make(chan protocol.FileInfo)
done := make(chan struct{})
progress := newByteCounter()
defer progress.Close()
newParallelHasher(w.Dir, w.BlockSize, w.Hashers, finishedChan, realToHashChan, progress, done, w.Cancel)
// A routine which actually emits the FolderScanProgress events
// every w.ProgressTicker ticks, until the hasher routines terminate.
go func() {
defer progress.Close()
for {
select {
case <-done:
@ -185,7 +186,7 @@ func (w *walker) walk() (chan protocol.FileInfo, error) {
case <-ticker.C:
current := progress.Total()
rate := progress.Rate()
l.Debugf("Walk %s %s current progress %d/%d at %.01f MB/s (%d%%)", w.Dir, w.Subs, current, total, rate/1024/1024, current*100/total)
l.Debugf("Walk %s %s current progress %d/%d at %.01f MiB/s (%d%%)", w.Dir, w.Subs, current, total, rate/1024/1024, current*100/total)
events.Default.Log(events.FolderScanProgress, map[string]interface{}{
"folder": w.Folder,
"current": current,