| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
import filecmp |
| 8 |
import os |
| 9 |
import shutil |
| 10 |
from pathlib import Path |
| 11 |
|
| 12 |
from rsyncfns import ( |
| 13 |
FROMDIR, SRCDIR, TMPDIR, TODIR, |
| 14 |
makepath, rmtree, run_rsync, test_fail, |
| 15 |
) |
| 16 |
|
| 17 |
|
| 18 |
makepath(FROMDIR, TODIR) |
| 19 |
shutil.copy2(SRCDIR / 'rsync.h', FROMDIR / 'text') |
| 20 |
shutil.copy2(SRCDIR / 'configure.ac', FROMDIR / 'extra') |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
os.chdir(TMPDIR) |
| 25 |
|
| 26 |
deep_dir = Path('to/foo/bar/baz/down/deep') |
| 27 |
|
| 28 |
|
| 29 |
def assert_file(path: Path, label: str, src: str = 'from/text') -> None: |
| 30 |
if not path.is_file(): |
| 31 |
test_fail(f"{label}: {path} not found") |
| 32 |
if not filecmp.cmp(path, src, shallow=False): |
| 33 |
test_fail(f"{label}: {path} content differs from {src}") |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
rmtree('to/foo') |
| 39 |
proc = run_rsync('-ai', 'from/text', str(deep_dir / 'new'), check=False) |
| 40 |
if proc.returncode == 0 or (deep_dir / 'new').exists(): |
| 41 |
test_fail("a transfer WITHOUT --mkpath created the missing intermediate path") |
| 42 |
|
| 43 |
nt |
| 44 |
|
| 45 |
run_rsync('-aiv', '--mkpath', 'from/text', str(deep_dir / 'new')) |
| 46 |
assert_file(deep_dir / 'new', "'new' file in deep dir") |
| 47 |
rmtree('to/foo') |
| 48 |
|
| 49 |
|
| 50 |
run_rsync('-aiv', '--mkpath', 'from/text', str(deep_dir) + '/') |
| 51 |
assert_file(deep_dir / 'text', "'text' file in deep dir (trailing-slash dest)") |
| 52 |
(deep_dir / 'text').unlink() |
| 53 |
|
| 54 |
|
| 55 |
(deep_dir / 'new').mkdir(parents=True, exist_ok=True) |
| 56 |
run_rsync('-aiv', '--mkpath', 'from/text', str(deep_dir / 'new')) |
| 57 |
assert_file(deep_dir / 'new' / 'text', "'text' file in pre-existing deep/new dir") |
| 58 |
|
| 59 |
|
| 60 |
run_rsync('-aiv', '--mkpath', 'from/text', str(deep_dir / 'new' / 'text2')) |
| 61 |
assert_file(deep_dir / 'new' / 'text2', "'text2' renamed file in pre-existing deep/new dir") |
| 62 |
rmtree('to/foo') |
| 63 |
|
| 64 |
e. |
| 65 |
run_rsync('-aiv', '--mkpath', 'from/', str(deep_dir)) |
| 66 |
assert_file(deep_dir / 'extra', "'extra' file in deep dir (multi-source, no trailing slash)", |
| 67 |
src='from/extra') |
| 68 |
rmtree('to/foo') |
| 69 |
|
| 70 |
h. |
| 71 |
run_rsync('-aiv', '--mkpath', 'from/', str(deep_dir) + '/') |
| 72 |
assert_file(deep_dir / 'text', "'text' file in deep dir (multi-source, trailing slash)") |
| 73 |
|
| 74 |
r. |
| 75 |
run_rsync('-aiv', '--mkpath', 'from/text', 'to_text') |
| 76 |
assert_file(Path('to_text'), "'to_text' file in current dir") |