Bump version to 1.0.51
This commit is contained in:
@@ -24,6 +24,15 @@ type ProgressLine struct {
|
||||
XferedBytes int64
|
||||
}
|
||||
|
||||
type ProgressFields struct {
|
||||
FileBytes int64
|
||||
Pct int
|
||||
SpeedBps int64
|
||||
EtaSeconds int
|
||||
XfrDone int
|
||||
XfrTotal int
|
||||
}
|
||||
|
||||
var (
|
||||
progressRegex = regexp.MustCompile(`\s*([\d,]+)\s+([\d,]+)\s+([\d%]+)\s*`)
|
||||
sentRegex = regexp.MustCompile(`sent\s+([\d,]+)\s+bytes`)
|
||||
@@ -32,6 +41,24 @@ var (
|
||||
filesRegex = regexp.MustCompile(`Number of files: ([\d,]+)`)
|
||||
)
|
||||
|
||||
var perFileProgressRegex = regexp.MustCompile(
|
||||
`^\s*(\d{1,3}(?:,\d{3})+)\s+(\d+)%\s+(\d+\.\d+)([kMG])B/s\s+(\d+:\d{2}:\d{2})(.*)`,
|
||||
)
|
||||
|
||||
var xfrRegex = regexp.MustCompile(`xfr#(\d+).*to-chk=(\d+)/(\d+)`)
|
||||
|
||||
func parseXfrSuffix(suffix string) (done, total int) {
|
||||
m := xfrRegex.FindStringSubmatch(suffix)
|
||||
if m == nil {
|
||||
return 0, 0
|
||||
}
|
||||
done, _ = strconv.Atoi(m[1])
|
||||
t, _ := strconv.Atoi(m[2])
|
||||
_ = t
|
||||
total, _ = strconv.Atoi(m[3])
|
||||
return done, total
|
||||
}
|
||||
|
||||
func ParseProgressLine(line string) *ProgressLine {
|
||||
if strings.Contains(line, "files to consider") || strings.Contains(line, "files...") {
|
||||
return &ProgressLine{Phase: "scanning"}
|
||||
@@ -74,3 +101,71 @@ func ParseFinalStats(output string) *RsyncStats {
|
||||
}
|
||||
return stats
|
||||
}
|
||||
|
||||
func isProgressOnlyLine(line string) bool {
|
||||
return perFileProgressRegex.MatchString(line)
|
||||
}
|
||||
|
||||
func parseProgressFields(line string) *ProgressFields {
|
||||
m := perFileProgressRegex.FindStringSubmatch(line)
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
bytes, _ := strconv.ParseInt(strings.ReplaceAll(m[1], ",", ""), 10, 64)
|
||||
pct, _ := strconv.Atoi(m[2])
|
||||
speed, _ := strconv.ParseFloat(m[3], 64)
|
||||
unit := m[4]
|
||||
eta := m[5]
|
||||
suffix := m[6]
|
||||
|
||||
speedBps := int64(speed * 1e6)
|
||||
switch unit {
|
||||
case "k", "K":
|
||||
speedBps = int64(speed * 1e3)
|
||||
case "m", "M":
|
||||
speedBps = int64(speed * 1e6)
|
||||
case "g", "G":
|
||||
speedBps = int64(speed * 1e9)
|
||||
}
|
||||
|
||||
etaSecs := 0
|
||||
parts := strings.Split(eta, ":")
|
||||
if len(parts) == 3 {
|
||||
h, _ := strconv.Atoi(parts[0])
|
||||
m, _ := strconv.Atoi(parts[1])
|
||||
s, _ := strconv.Atoi(parts[2])
|
||||
etaSecs = h*3600 + m*60 + s
|
||||
}
|
||||
|
||||
pf := &ProgressFields{
|
||||
FileBytes: bytes,
|
||||
Pct: pct,
|
||||
SpeedBps: speedBps,
|
||||
EtaSeconds: etaSecs,
|
||||
}
|
||||
|
||||
if suffix != "" {
|
||||
done, total := parseXfrSuffix(suffix)
|
||||
pf.XfrDone = done
|
||||
pf.XfrTotal = total
|
||||
}
|
||||
|
||||
return pf
|
||||
}
|
||||
|
||||
func isFileNameLine(line string) bool {
|
||||
if line == "" || strings.TrimSpace(line) == "" {
|
||||
return false
|
||||
}
|
||||
if strings.Contains(line, "sending incremental file list") ||
|
||||
strings.Contains(line, "building file list") ||
|
||||
strings.Contains(line, "cannot open") ||
|
||||
strings.Contains(line, "skipping non-regular") ||
|
||||
strings.HasPrefix(line, "sent ") ||
|
||||
strings.HasPrefix(line, "total ") ||
|
||||
strings.HasPrefix(line, "Number of files:") ||
|
||||
strings.Contains(line, "bytes received") {
|
||||
return false
|
||||
}
|
||||
return !isProgressOnlyLine(line)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user