MCPcopy
hub / github.com/rclone/rclone / startProgress

Function startProgress

cmd/progress.go:27–71  ·  view source on GitHub ↗

startProgress starts the progress bar printing It returns a func which should be called to stop the stats.

()

Source from the content-addressed store, hash-verified

25//
26// It returns a func which should be called to stop the stats.
27func startProgress() func() {
28 stopStats := make(chan struct{})
29 oldSyncPrint := operations.SyncPrintf
30
31 if !log.Redirected() {
32 // Intercept the log calls if not logging to file or syslog
33 log.Handler.SetOutput(func(level slog.Level, text string) {
34 printProgress(text)
35 })
36 }
37
38 // Intercept output from functions such as HashLister to stdout
39 operations.SyncPrintf = func(format string, a ...any) {
40 printProgress(fmt.Sprintf(format, a...))
41 }
42
43 var wg sync.WaitGroup
44 wg.Go(func() {
45 progressInterval := defaultProgressInterval
46 if ShowStats() && *statsInterval > 0 {
47 progressInterval = *statsInterval
48 }
49 ticker := time.NewTicker(progressInterval)
50 for {
51 select {
52 case <-ticker.C:
53 printProgress("")
54 case <-stopStats:
55 ticker.Stop()
56 printProgress("")
57 if !log.Redirected() {
58 // Reset intercept of the log calls
59 log.Handler.ResetOutput()
60 }
61 operations.SyncPrintf = oldSyncPrint
62 fmt.Println("")
63 return
64 }
65 }
66 })
67 return func() {
68 close(stopStats)
69 wg.Wait()
70 }
71}
72
73// state for the progress printing
74var (

Callers 1

RunFunction · 0.85

Calls 8

RedirectedFunction · 0.92
printProgressFunction · 0.85
ShowStatsFunction · 0.85
closeFunction · 0.85
ResetOutputMethod · 0.80
WaitMethod · 0.65
SetOutputMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…