Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* (percent / speed / eta) and the --stats "Total transferred file
* size" line. Pure (no android.*, no I/O), so it is unit-testable
* on a plain JVM and clonable by an external host (Share-export,
* S14 step 1). Regexes are unchanged from the previous inline
* parsing in RsyncManager.
* S14 step 1). The progress regex accepts both the rsync 3.5.1
* byte column and the 3.5.2 one with a "B" unit.
* ============================================================================
*/
package org.appdevforall.k2go.sync.domain;
Expand All @@ -34,9 +34,9 @@ private RsyncProgress(long bytes, int percent, String speed, String eta) {
// ADFA-5160: capture the leading transferred-bytes column (with grouping separators)
// as well as the percent. rsync's own percent divides by an estimate that grows as it
// discovers files, so it jumps around; the byte count is a stable numerator the caller
// can divide by a known total instead.
// can divide by a known total instead. rsync 3.5.2 appends a "B" unit to the bytes.
private static final Pattern PROGRESS =
Pattern.compile("([\\d,]+)\\s+(\\d+)%\\s+([\\d\\.]+[a-zA-Z/s]+)\\s+([\\d:]+)");
Pattern.compile("([\\d,]+)B?\\s+(\\d+)%\\s+([\\d\\.]+[a-zA-Z/s]+)\\s+([\\d:]+)");

private static final Pattern STATS =
Pattern.compile("Total transferred file size:\\s+([\\d,\\.]+)\\s+bytes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@ public void parsesLeadingTransferredBytesWithSeparators() {
assertEquals(88, p.percent);
}

// K2GO-550: rsync 3.5.2 writes the byte column with a "B" unit.
@Test
public void parsesByteColumnWithUnit() {
RsyncProgress p = RsyncProgress.parse(" 122,191,872B 58% 122MB/s 0:00:00");
assertNotNull(p);
assertEquals(122191872L, p.bytes);
assertEquals(58, p.percent);
assertEquals("122MB/s", p.speed);
assertEquals("0:00:00", p.eta);
}

// Real rsync 3.5.2 output (OnePlus 7T, shipped librsync.so): first sample and a final line
// with the (xfr#, to-chk) suffix.
@Test
public void parsesRsync352Lines() {
RsyncProgress first = RsyncProgress.parse(" 32,768B 0% 0B/s 0:00:00 ");
assertNotNull(first);
assertEquals(32768L, first.bytes);
assertEquals("0B/s", first.speed);

RsyncProgress last = RsyncProgress.parse(
" 30,000,000B 100% 143MB/s 0:00:00 (xfr#1, to-chk=0/2)");
assertNotNull(last);
assertEquals(30000000L, last.bytes);
assertEquals(100, last.percent);
assertEquals("143MB/s", last.speed);
}

@Test
public void parsesRsync352StatsLine() {
assertEquals(30000000L, RsyncProgress.parseTransferredBytes(
"Total transferred file size: 30,000,000 bytes", -1L));
}

@Test
public void returnsNullWhenNoProgressToken() {
assertNull(RsyncProgress.parse("sending incremental file list"));
Expand Down
Loading