| 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 |
import time |
| 26 |
|
| 27 |
from rsyncfns import ( |
| 28 |
SCRATCHDIR, claim_ports, require_tcp, start_rsyncd, test_fail, |
| 29 |
) |
| 30 |
import rsync_proto as rp |
| 31 |
|
| 32 |
PORT = 12960 |
| 33 |
BACKREF_GNUM = 1 |
| 34 |
require_tcp("the pure-Python sender needs a real TCP daemon; run with --use-tcp") |
| 35 |
claim_ports(PORT) |
| 36 |
|
| 37 |
mod = SCRATCHDIR / 'hg-mod' |
| 38 |
mod.mkdir(parents=True, exist_ok=True) |
| 39 |
conf = SCRATCHDIR / 'hg.conf' |
| 40 |
log = SCRATCHDIR / 'hg.log' |
| 41 |
conf.write_text(f"""\ |
| 42 |
pid file = {SCRATCHDIR}/hg-rsyncd.pid |
| 43 |
use chroot = no |
| 44 |
log file = {log} |
| 45 |
|
| 46 |
[mod] |
| 47 |
path = {mod} |
| 48 |
read only = no |
| 49 |
""") |
| 50 |
start_rsyncd(conf, PORT) |
| 51 |
|
| 52 |
before = log.read_text(errors='replace') if log.exists() else '' |
| 53 |
s = rp.DaemonSender('127.0.0.1', PORT) |
| 54 |
s.handshake('mod', ['--server', '-rHe.iLsfxCIu', '.', 'mod/'], greeting_version=30) |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
d = rp.FileEntry('d', mode=rp.S_IFDIR | 0o755, length=0, extra_flags=rp.XMIT_TOP_DIR) |
| 59 |
f = rp.FileEntry('f', mode=rp.S_IFREG | 0o644, length=100) |
| 60 |
s.send_data(d.encode() + f.encode() + rp.end_of_flist(0, s.protocol)) |
| 61 |
|
| 62 |
|
| 63 |
h = rp.FileEntry('d/h', mode=rp.S_IFREG | 0o644, length=0, hlink_ndx=BACKREF_GNUM) |
| 64 |
s.send_data(s.w_ndx(rp.NDX_FLIST_OFFSET - 0) + h.encode() + rp.end_of_flist(0, s.protocol)) |
| 65 |
s.drain(timeout=2.0) |
| 66 |
s.close() |
| 67 |
|
| 68 |
refused = False |
| 69 |
needle = 'hard-link gnum %d precedes flist start' % BACKREF_GNUM |
| 70 |
for _ in range(50): |
| 71 |
new = log.read_text(errors='replace')[len(before):] |
| 72 |
if needle in new: |
| 73 |
refused = True |
| 74 |
break |
| 75 |
time.sleep(0.1) |
| 76 |
|
| 77 |
if not refused: |
| 78 |
new = log.read_text(errors='replace')[len(before):] |
| 79 |
test_fail( |
| 80 |
"generator did not reject an undeclared back-reference hard-link gnum " |
| 81 |
"-- it hit the match_gnums() assert(gnum >= ndx_start) and aborted.\n" |
| 82 |
f"daemon log:\n{new}") |
| 83 |
|
| 84 |
print("proto-hlink-gnum: generator rejected an undeclared back-reference " |
| 85 |
"hard-link gnum (no assert abort).") |