| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
import os |
| 8 |
|
| 9 |
from rsyncfns import SCRATCHDIR, run_rsync, test_fail, test_skipped |
| 10 |
|
| 11 |
base = SCRATCHDIR / 'logctl' |
| 12 |
src = base / 'src' |
| 13 |
dst = base / 'dst' |
| 14 |
src.mkdir(parents=True, exist_ok=True) |
| 15 |
dst.mkdir(parents=True, exist_ok=True) |
| 16 |
log = base / 'rsync.log' |
| 17 |
|
| 18 |
srcb = os.fsencode(str(src)) |
| 19 |
made = 0 |
| 20 |
for raw in (b'c0_\x1b_esc', b'c1_\x9b_csi'): |
| 21 |
try: |
| 22 |
with open(srcb + b'/' + raw, 'wb') as fh: |
| 23 |
fh.write(b'x') |
| 24 |
made += 1 |
| 25 |
except OSError: |
| 26 |
pass |
| 27 |
if made == 0: |
| 28 |
test_skipped("filesystem rejects control-char filenames") |
| 29 |
|
| 30 |
run_rsync('-rv', f'--log-file={log}', f'{src}/', f'{dst}/') |
| 31 |
|
| 32 |
data = log.read_bytes() |
| 33 |
if b'\x1b' in data: |
| 34 |
test_fail("raw C0 ESC (0x1b) byte left un-escaped in the log file") |
| 35 |
if b'\x9b' in data: |
| 36 |
test_fail("raw C1 CSI (0x9b) byte left un-escaped in the log file") |
| 37 |
if b'\\#' not in data: |
| 38 |
test_fail("expected escaped \\#NNN sequences in the log file, found none") |
| 39 |
|
| 40 |
print(f'log-control-chars: {made} control-char name(s) escaped in the log file') |