| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
import re |
| 32 |
import subprocess |
| 33 |
|
| 34 |
from rsyncfns import ( |
| 35 |
SCRATCHDIR, make_data_file, makepath, rmtree, rsync_argv, start_test_daemon, |
| 36 |
test_fail, write_daemon_conf, |
| 37 |
) |
| 38 |
|
| 39 |
DAEMON_PORT = 12915 |
| 40 |
DATA_SIZE = 40000 |
| 41 |
|
| 42 |
mod = SCRATCHDIR / 'bakmod' |
| 43 |
src = SCRATCHDIR / 'src915' |
| 44 |
rmtree(mod) |
| 45 |
rmtree(src) |
| 46 |
makepath(mod / '01', src) |
| 47 |
make_data_file(src / 'f.dat', DATA_SIZE) |
| 48 |
|
| 49 |
|
| 50 |
import shutil |
| 51 |
shutil.copy2(src / 'f.dat', mod / '01' / 'f.dat') |
| 52 |
|
| 53 |
conf = write_daemon_conf([ |
| 54 |
('bak', {'path': str(mod), 'read only': 'no'}), |
| 55 |
]) |
| 56 |
url = start_test_daemon(conf, DAEMON_PORT) |
| 57 |
|
| 58 |
|
| 59 |
def push(opt): |
| 60 |
"""Fresh dest 00, push src/ into bak/00/ with the given alt-basis option. |
| 61 |
Returns (rc, stdout).""" |
| 62 |
rmtree(mod / '00') |
| 63 |
proc = subprocess.run( |
| 64 |
rsync_argv('-a', '--stats', opt, f'{src}/', f'{url}bak/00/'), |
| 65 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) |
| 66 |
return proc.returncode, (proc.stdout or '') |
| 67 |
|
| 68 |
|
| 69 |
def same_inode(a, b): |
| 70 |
sa, sb = a.stat(), b.stat() |
| 71 |
return (sa.st_dev, sa.st_ino) == (sb.st_dev, sb.st_ino) |
| 72 |
|
| 73 |
|
| 74 |
def literal_bytes(out): |
| 75 |
m = re.search(r'Literal data:\s*([\d,]+)', out) |
| 76 |
return int(m.group(1).replace(',', '')) if m else -1 |
| 77 |
|
| 78 |
|
| 79 |
regressions = [] |
| 80 |
basis = mod / '01' / 'f.dat' |
| 81 |
|
| 82 |
|
| 83 |
rc, out = push('--link-dest=../01') |
| 84 |
if rc != 0: |
| 85 |
test_fail(f"--link-dest push failed unexpectedly (rc={rc}):\n{out}") |
| 86 |
dest = mod / '00' / 'f.dat' |
| 87 |
if not dest.is_file(): |
| 88 |
test_fail(f"--link-dest: destination file missing ({dest})") |
| 89 |
if not same_inode(dest, basis): |
| 90 |
regressions.append("--link-dest=../01 did not hard-link to the basis " |
| 91 |
"(file re-transferred)") |
| 92 |
|
| 93 |
|
| 94 |
rc, out = push('--copy-dest=../01') |
| 95 |
if rc != 0: |
| 96 |
test_fail(f"--copy-dest push failed unexpectedly (rc={rc}):\n{out}") |
| 97 |
dest = mod / '00' / 'f.dat' |
| 98 |
if not dest.is_file(): |
| 99 |
test_fail(f"--copy-dest: destination file missing ({dest})") |
| 100 |
lit = literal_bytes(out) |
| 101 |
if lit > DATA_SIZE // 2: |
| 102 |
regressions.append(f"--copy-dest=../01 re-sent the data over the wire " |
| 103 |
f"(Literal data={lit}, basis not used)") |
| 104 |
|
| 105 |
|
| 106 |
rc, out = push('--compare-dest=../01') |
| 107 |
if rc != 0: |
| 108 |
test_fail(f"--compare-dest push failed unexpectedly (rc={rc}):\n{out}") |
| 109 |
if (mod / '00' / 'f.dat').is_file(): |
| 110 |
regressions.append("--compare-dest=../01 created the file in the dest " |
| 111 |
"(basis not matched, so the file was transferred)") |
| 112 |
|
| 113 |
if regressions: |
| 114 |
test_fail( |
| 115 |
"#915/#930: a daemon receiver ignored a RELATIVE alt-basis dir (../01) -- " |
| 116 |
"the secure resolver must honour an in-module `..` climb to the sibling " |
| 117 |
"basis on every platform:\n - " + "\n - ".join(regressions)) |
| 118 |
|