| 1 |
|
| 2 |
"""Coverage of --inplace at depth. |
| 3 |
|
| 4 |
--inplace updates the destination file directly instead of writing a temp copy |
| 5 |
and renaming it over the original, so across a delta update the destination |
| 6 |
keeps the SAME inode. Without --inplace the receiver creates a fresh temp file |
| 7 |
and renames it, giving the destination a NEW inode. Both behaviours hinge on |
| 8 |
how the receiver resolves the destination directory and (for the default mode) |
| 9 |
performs the temp->final rename, which the path restructure rewrites; verify |
| 10 |
them on a file >=3 levels deep. |
| 11 |
""" |
| 12 |
|
| 13 |
import os |
| 14 |
|
| 15 |
from rsyncfns import ( |
| 16 |
FROMDIR, TODIR, |
| 17 |
assert_same, make_tree, rmtree, run_rsync, test_fail, |
| 18 |
) |
| 19 |
|
| 20 |
src = FROMDIR |
| 21 |
deep = os.path.join('d1', 'd2', 'd3', 'f3') |
| 22 |
|
| 23 |
|
| 24 |
def seed(): |
| 25 |
rmtree(src) |
| 26 |
rmtree(TODIR) |
| 27 |
make_tree(src, depth=3, data=True, data_size=200000) |
| 28 |
|
| 29 |
|
| 30 |
def inode(path): |
| 31 |
return os.stat(path).st_ino |
| 32 |
|
| 33 |
|
| 34 |
def modify_deep(): |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
p = src / deep |
| 40 |
data = bytearray(p.read_bytes()) |
| 41 |
data[1000:1100] = bytes((b ^ 0xFF) for b in data[1000:1100]) |
| 42 |
p.write_bytes(bytes(data)) |
| 43 |
st = os.stat(p) |
| 44 |
os.utime(p, (st.st_atime, st.st_mtime + 100)) |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
seed() |
| 49 |
run_rsync('-a', f'{src}/', f'{TODIR}/') |
| 50 |
ino_before = inode(TODIR / deep) |
| 51 |
|
| 52 |
modify_deep() |
| 53 |
run_rsync('-a', '--inplace', '--no-whole-file', f'{src}/', f'{TODIR}/') |
| 54 |
assert_same(TODIR / deep, src / deep, label='inplace content') |
| 55 |
if inode(TODIR / deep) != ino_before: |
| 56 |
test_fail("--inplace changed the destination inode at depth " |
| 57 |
f"({ino_before} -> {inode(TODIR / deep)})") |
| 58 |
|
| 59 |
|
| 60 |
seed() |
| 61 |
run_rsync('-a', f'{src}/', f'{TODIR}/') |
| 62 |
ino_before = inode(TODIR / deep) |
| 63 |
|
| 64 |
modify_deep() |
| 65 |
run_rsync('-a', '--no-whole-file', f'{src}/', f'{TODIR}/') |
| 66 |
assert_same(TODIR / deep, src / deep, label='default content') |
| 67 |
if inode(TODIR / deep) == ino_before: |
| 68 |
test_fail("default (non-inplace) delta update unexpectedly kept the " |
| 69 |
"destination inode at depth -- temp+rename did not run") |
| 70 |
|
| 71 |
print("inplace: same-inode update at depth verified; default replaces inode") |