| 1 |
"""Pin that a relative `--backup-dir` is relative to the DESTINATION dir. |
| 2 |
|
| 3 |
The rsync(1) `--backup-dir` entry says "if you specify a relative path, the |
| 4 |
backup directory will be relative to the destination directory". This test |
| 5 |
measures it: with `--backup-dir=bak` and a destination `d`, the replaced file's |
| 6 |
backup lands at `d/bak/...`, not under the invoking cwd. |
| 7 |
|
| 8 |
Pure local client behaviour: no daemon/root/tcp. Cross-version: expected |
| 9 |
identical against --rsync-bin=old_versions/rsync_3.2.7. |
| 10 |
""" |
| 11 |
|
| 12 |
import subprocess |
| 13 |
|
| 14 |
from rsyncfns import SCRATCHDIR, rmtree, rsync_argv, test_fail |
| 15 |
|
| 16 |
base = SCRATCHDIR / 'backup-dir-rel' |
| 17 |
rmtree(base) |
| 18 |
base.mkdir(parents=True) |
| 19 |
|
| 20 |
src = base / 'src' |
| 21 |
dst = base / 'dst' |
| 22 |
src.mkdir() |
| 23 |
dst.mkdir() |
| 24 |
|
| 25 |
(dst / 'file').write_text('OLD\n') |
| 26 |
(src / 'file').write_text('NEWER-CONTENT\n') |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
subprocess.run( |
| 31 |
rsync_argv('-a', '-b', '--backup-dir=bak', f'{src}/', f'{dst}/'), |
| 32 |
cwd=str(base), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 33 |
|
| 34 |
dest_rel = dst / 'bak' / 'file' |
| 35 |
cwd_rel = base / 'bak' / 'file' |
| 36 |
|
| 37 |
if cwd_rel.exists(): |
| 38 |
test_fail("--backup-dir: relative path was interpreted relative to the cwd, " |
| 39 |
"not the destination dir") |
| 40 |
if not dest_rel.is_file() or dest_rel.read_text() != 'OLD\n': |
| 41 |
test_fail("--backup-dir: backup did not land under the destination dir " |
| 42 |
"(expected dst/bak/file with the old content)") |
| 43 |
if (dst / 'file').read_text() != 'NEWER-CONTENT\n': |
| 44 |
test_fail("--backup-dir: destination file was not updated") |
| 45 |
|
| 46 |
print("backup-dir-relative: a relative --backup-dir lands under the destination " |
| 47 |
"dir (dst/bak/file), not the invoking cwd") |