| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
import os |
| 12 |
|
| 13 |
from mutatefns import TARGET, assert_no_protocol_abort, run_mutating_transfer |
| 14 |
from rsyncfns import test_fail |
| 15 |
|
| 16 |
BIG = 512 * 1024 |
| 17 |
SMALL = 4 * 1024 |
| 18 |
|
| 19 |
|
| 20 |
def setup(src): |
| 21 |
|
| 22 |
with open(src / TARGET, 'wb') as fh: |
| 23 |
fh.write(os.urandom(BIG)) |
| 24 |
|
| 25 |
|
| 26 |
def mutate(src): |
| 27 |
|
| 28 |
with open(src / TARGET, 'r+b') as fh: |
| 29 |
fh.truncate(SMALL) |
| 30 |
fh.flush() |
| 31 |
os.fsync(fh.fileno()) |
| 32 |
|
| 33 |
|
| 34 |
proc, src, dst = run_mutating_transfer(setup, mutate) |
| 35 |
assert_no_protocol_abort(proc) |
| 36 |
|
| 37 |
src_size = (src / TARGET).stat().st_size |
| 38 |
if src_size != SMALL: |
| 39 |
test_fail(f"test setup: source did not shrink (size {src_size})") |
| 40 |
|
| 41 |
|
| 42 |
if not (dst / 'aaa_pacer').is_file(): |
| 43 |
test_fail("the pacer file was not transferred after the shrink") |
| 44 |
|
| 45 |
|
| 46 |
if (dst / TARGET).is_file(): |
| 47 |
if (dst / TARGET).stat().st_size > BIG: |
| 48 |
test_fail("destination is larger than the original flist size") |
| 49 |
|
| 50 |
print(f"change-shrink: source shrank {BIG}->{SMALL} mid-transfer; rsync exit " |
| 51 |
f"{proc.returncode}, no protocol abort, later files intact") |