| 1 |
|
| 2 |
"""Absolute --relative source cleanup must use the source's absolute parent.""" |
| 3 |
|
| 4 |
import subprocess |
| 5 |
|
| 6 |
from rsyncfns import SCRATCHDIR, rmtree, rsync_argv, test_fail |
| 7 |
|
| 8 |
|
| 9 |
base = SCRATCHDIR.resolve() / "sender-remove-source-relative-anchor" |
| 10 |
source = base / "source/sub/file" |
| 11 |
dest = base / "dest" |
| 12 |
rmtree(base) |
| 13 |
source.parent.mkdir(parents=True) |
| 14 |
dest.mkdir() |
| 15 |
source.write_text("absolute-relative-source\n", encoding="utf-8") |
| 16 |
|
| 17 |
proc = subprocess.run( |
| 18 |
rsync_argv("-aR", "--remove-source-files", str(source), str(dest) + "/"), |
| 19 |
stdout=subprocess.PIPE, |
| 20 |
stderr=subprocess.STDOUT, |
| 21 |
text=True, |
| 22 |
) |
| 23 |
if proc.returncode != 0: |
| 24 |
test_fail( |
| 25 |
"absolute -R --remove-source-files copied the file but failed cleanup " |
| 26 |
f"(rc={proc.returncode}):\n{proc.stdout}" |
| 27 |
) |
| 28 |
if source.exists(): |
| 29 |
test_fail("absolute -R --remove-source-files left its source behind") |
| 30 |
|
| 31 |
copies = [ |
| 32 |
path for path in dest.rglob("file") |
| 33 |
if path.is_file() and path.read_text(encoding="utf-8") |
| 34 |
== "absolute-relative-source\n" |
| 35 |
] |
| 36 |
if len(copies) != 1: |
| 37 |
test_fail(f"destination did not contain exactly one transferred file: {copies}") |
| 38 |
|
| 39 |
print("absolute --relative source was copied and removed through its real parent") |