| 1 |
|
| 2 |
"""Regression test: `%%` in --out-format outputs a literal `%`. |
| 3 |
|
| 4 |
# Verifies: SW-REQ-166 |
| 5 |
|
| 6 |
The log_formatted() switch in log.c had no `case '%'`, so `%%` left the |
| 7 |
first `%` in place and re-parsed the second `%` as the start of a new |
| 8 |
specifier. This test transfers a file with `--out-format='100%% done %f'` |
| 9 |
and asserts the output contains `100% done <filename>` (a single literal |
| 10 |
percent, a space, the word "done", and the expanded filename). |
| 11 |
""" |
| 12 |
|
| 13 |
import subprocess |
| 14 |
|
| 15 |
from rsyncfns import ( |
| 16 |
FROMDIR, TODIR, |
| 17 |
forced_protocol, makepath, rmtree, rsync_argv, test_fail, |
| 18 |
) |
| 19 |
|
| 20 |
src = FROMDIR |
| 21 |
|
| 22 |
|
| 23 |
rmtree(src) |
| 24 |
rmtree(TODIR) |
| 25 |
makepath(src) |
| 26 |
(src / 'percentfile').write_text("data\n") |
| 27 |
|
| 28 |
|
| 29 |
p = subprocess.run( |
| 30 |
rsync_argv('-a', '--out-format=100%% done %f', f'{src}/', f'{TODIR}/'), |
| 31 |
capture_output=True, text=True, |
| 32 |
) |
| 33 |
if p.returncode != 0: |
| 34 |
test_fail(f"rsync exited {p.returncode}:\n{p.stderr}") |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
if '100% done ' not in p.stdout or 'percentfile' not in p.stdout: |
| 42 |
test_fail( |
| 43 |
"expected '100% done ' (a single literal percent) and 'percentfile' in " |
| 44 |
f"--out-format output, got:\n{p.stdout}" |
| 45 |
) |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
(src / 'percentfile').chmod(0o640) |
| 52 |
p = subprocess.run( |
| 53 |
rsync_argv('-a', '--out-format=%%i %n', f'{src}/', f'{TODIR}/'), |
| 54 |
capture_output=True, text=True, |
| 55 |
) |
| 56 |
if p.returncode != 0: |
| 57 |
test_fail(f"rsync exited {p.returncode}:\n{p.stderr}") |
| 58 |
(src / 'percentfile').chmod(0o600) |
| 59 |
p = subprocess.run( |
| 60 |
rsync_argv('-a', '--out-format=%%i %n', f'{src}/', f'{TODIR}/'), |
| 61 |
capture_output=True, text=True, |
| 62 |
) |
| 63 |
if p.returncode != 0: |
| 64 |
test_fail(f"rsync exited {p.returncode}:\n{p.stderr}") |
| 65 |
if 'percentfile' in p.stdout: |
| 66 |
test_fail( |
| 67 |
"'%%i' misdetected as itemizing: an attribute-only change was logged " |
| 68 |
f"by --out-format='%%i %n':\n{p.stdout}" |
| 69 |
) |
| 70 |
|
| 71 |
|
| 72 |
(src / 'percentfile').write_text("data2\n") |
| 73 |
p = subprocess.run( |
| 74 |
rsync_argv('-a', '--out-format=%%i %n', f'{src}/', f'{TODIR}/'), |
| 75 |
capture_output=True, text=True, |
| 76 |
) |
| 77 |
if p.returncode != 0: |
| 78 |
test_fail(f"rsync exited {p.returncode}:\n{p.stderr}") |
| 79 |
if '%i percentfile' not in p.stdout: |
| 80 |
test_fail( |
| 81 |
"expected literal '%i percentfile' for a transferred file with " |
| 82 |
f"--out-format='%%i %n', got:\n{p.stdout}" |
| 83 |
) |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
import re |
| 98 |
|
| 99 |
def checksum_for(fmt): |
| 100 |
(src / 'percentfile').write_text("data3\n") |
| 101 |
rmtree(TODIR) |
| 102 |
r = subprocess.run( |
| 103 |
rsync_argv('-a', '-c', f'--out-format={fmt} %n', f'{src}/', f'{TODIR}/'), |
| 104 |
capture_output=True, text=True, |
| 105 |
) |
| 106 |
if r.returncode != 0: |
| 107 |
test_fail(f"rsync -c exited {r.returncode} for --out-format={fmt!r}:\n{r.stderr}") |
| 108 |
m = re.search(r'([0-9a-f]+) percentfile', r.stdout) |
| 109 |
if not m: |
| 110 |
test_fail(f"no '<hex> percentfile' in --out-format={fmt!r} output:\n{r.stdout}") |
| 111 |
return m.group(1) |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
proto = forced_protocol() |
| 120 |
if proto is None or proto >= 30: |
| 121 |
|
| 122 |
|
| 123 |
plain = checksum_for('%C') |
| 124 |
wide = checksum_for('%' + '0' * 30 + '%C') |
| 125 |
if not wide.endswith(plain): |
| 126 |
test_fail( |
| 127 |
f"over-wide %C rendered ...{wide[-len(plain):]!r} but plain %C rendered " |
| 128 |
f"{plain!r}: log_format_has()/log_formatted() disagree on the escape position" |
| 129 |
) |
| 130 |
|
| 131 |
print("ki58-log-format-percent: %% literal-percent escape verified") |