#!/usr/bin/env python3 """An aborted in-place update must not relax an existing file's mode. The proposed-3.5 receiver retries an EACCES output open by chmod'ing an existing output or in-place partial file to 0600. This test's fake remote sender closes after the receiver has requested the file and before sending any file-data token. The transfer must fail, but mode 0444 must survive. A normal successful --inplace update of a read-only file is also checked so that the 3.5 compatibility feature remains intact. """ import os import select import struct import subprocess import sys import rsync_proto as rp from rsyncfns import SCRATCHDIR, makepath, rmtree, rsync_argv, test_fail CF_INPLACE_PARTIAL_DIR = 1 << 6 FNAMECMP_PARTIAL_DIR = 0x81 ITEM_BASIS_TYPE_FOLLOWS = 1 << 11 def write_all(data): view = memoryview(data) while view: n = os.write(1, view) if n <= 0: raise RuntimeError("short write to rsync client") view = view[n:] def read_exact(n, timeout=10): out = bytearray() while len(out) < n: ready, _, _ = select.select([0], [], [], timeout) if not ready: raise RuntimeError(f"timeout reading {n} protocol bytes") chunk = os.read(0, n - len(out)) if not chunk: raise RuntimeError(f"EOF after {len(out)}/{n} protocol bytes") out += chunk return bytes(out) def frame(payload): word = ((rp.MPLEX_BASE + rp.MSG_DATA) << 24) | len(payload) return struct.pack("> 24) - rp.MPLEX_BASE payload = read_exact(length) if length else b"" if tag != rp.MSG_DATA: continue data += payload if len(data) >= 7 and b"\x01" in data[4:]: return if len(data) > 1024 * 1024: break raise RuntimeError(f"generator did not request index 0: {data[:64].hex()}") def fake_sender(basis_type): write_all(rp.w_int(30)) client_protocol = struct.unpack("