@@ -20,11 +20,12 @@ type Task struct {
2020
2121// State contains information about rsync process
2222type State struct {
23- Remain int `json:"remain"`
24- Total int `json:"total"`
25- Speed string `json:"speed"`
26- Progress float64 `json:"progress"`
27- Filename string `json:"filename"`
23+ TotalProgress int `json:"total_progress"`
24+ Remain int `json:"remain"`
25+ Total int `json:"total"`
26+ Speed string `json:"speed"`
27+ Progress float64 `json:"progress"`
28+ Filename string `json:"filename"`
2829}
2930
3031// Log contains raw stderr and stdout outputs
@@ -121,6 +122,7 @@ func processStdout(wg *sync.WaitGroup, task *Task, stdout io.Reader) {
121122
122123 progressMatcher := newMatcher (`\(.+-chk=(\d+.\d+)` )
123124 speedMatcher := newMatcher (`(\d+\.\d+.{2}\/s)` )
125+ totalProgressMatcher := newMatcher (`(\d+)%` )
124126
125127 // Extract data from strings:
126128 // 999,999 99% 999.99kB/s 0:00:59 (xfr#9, to-chk=999/9999)
@@ -139,6 +141,9 @@ func processStdout(wg *sync.WaitGroup, task *Task, stdout io.Reader) {
139141 task .state .Speed = getTaskSpeed (speedMatcher .ExtractAllStringSubmatch (logStr , 2 ))
140142 }
141143
144+ if totalProgressMatcher .Match (logStr ) {
145+ task .state .TotalProgress = getTaskTotalProgress (totalProgressMatcher .Extract (logStr ))
146+ }
142147 if isFilename (logStr ) {
143148 task .state .Filename = logStr
144149 }
@@ -157,6 +162,11 @@ func processStderr(wg *sync.WaitGroup, task *Task, stderr io.Reader) {
157162 }
158163}
159164
165+ func getTaskTotalProgress (totalProgress string ) int {
166+ total , _ := strconv .Atoi (totalProgress )
167+ return total
168+ }
169+
160170func getTaskProgress (remTotalString string ) (int , int ) {
161171 const remTotalSeparator = "/"
162172 const numbersCount = 2
0 commit comments