| 1 | #!/usr/bin/env python3 |
| 2 | # rsync -aR (--relative) must transfer file CONTENT, not just the directory tree. |
| 3 | # |
| 4 | # Regression for a 3.5.0-dev sender bug: the symlink-race-confined content open |
| 5 | # became secure_relative_open(NULL, fname, O_RDONLY|O_NOFOLLOW, 0), and |
| 6 | # secure_relative_open() rejects an ABSOLUTE relpath with EINVAL before opening. |
| 7 | # With --relative the sender keeps the full (absolute) source path as fname, so |
| 8 | # every regular file failed to open: directories/symlinks still transferred, but |
| 9 | # the files arrived empty/missing and the run exited 23 ("send_files failed to |
| 10 | # open ...: Invalid argument (22)"). A near-silent data-loss bug for the very |
| 11 | # common "rsync -aR /abs/path backup/" pattern. 3.4.x was unaffected. |
| 12 | # |
| 13 | # Plain transfer, no root or special features -- this must pass everywhere. |
| 14 | |
| 15 | from pathlib import Path |
| 16 | |
| 17 | from rsyncfns import SCRATCHDIR, makepath, rmtree, run_rsync, test_fail |
| 18 | |
| 19 | base = SCRATCHDIR / 'relcontent' |
| 20 | src = base / 'src' / 'sub' |
| 21 | dest = base / 'dest' |
| 22 | rmtree(base) |
| 23 | makepath(src, dest) |
| 24 | |
| 25 | payload = 'hello relative content\n' |
| 26 | (src / 'file').write_text(payload) |
| 27 | |
| 28 | # --relative with an ABSOLUTE source path: fname on the sender is absolute, the |
| 29 | # exact trigger. check=True fails the test if rsync exits non-zero (the buggy |
| 30 | # sender exits 23 here). |
| 31 | abs_file = str((src / 'file').resolve()) |
| 32 | run_rsync('-aR', abs_file, str(dest) + '/') |
| 33 | |
| 34 | # -R mirrors the absolute source path under dest: dest/<abs_file without leading />. |
| 35 | landed = dest / abs_file.lstrip('/') |
| 36 | if not landed.is_file(): |
| 37 | test_fail(f"rsync -aR did not create {landed} (only the tree, no file?)") |
| 38 | got = landed.read_text() |
| 39 | if got != payload: |
| 40 | test_fail(f"rsync -aR transferred empty/wrong content: {got!r} != {payload!r}") |
| 41 | |
| 42 | print("relative-content: rsync -aR transfers file content for an absolute source") |