| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import os |
| 18 |
import subprocess |
| 19 |
|
| 20 |
from rsyncfns import SCRATCHDIR, makepath, rmtree, rsync_argv, test_fail |
| 21 |
|
| 22 |
|
| 23 |
def itemize(*args): |
| 24 |
p = subprocess.run(rsync_argv('-ai', *args), capture_output=True, text=True) |
| 25 |
return p.returncode, p.stdout + p.stderr |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
mk = SCRATCHDIR / 'mk' |
| 30 |
rmtree(mk) |
| 31 |
makepath(mk / 'from') |
| 32 |
(mk / 'from' / 'src').write_text("payload\n") |
| 33 |
|
| 34 |
drc, dry = itemize('--dry-run', '--mkpath', |
| 35 |
str(mk / 'from' / 'src'), str(mk / 'dndir' / 'dst')) |
| 36 |
rc, real = itemize('--mkpath', str(mk / 'from' / 'src'), str(mk / 'rdir' / 'dst')) |
| 37 |
if drc != 0: |
| 38 |
print(dry) |
| 39 |
test_fail("--mkpath file-to-file --dry-run failed (#880)") |
| 40 |
if not (mk / 'rdir' / 'dst').exists(): |
| 41 |
test_fail("--mkpath real run did not create the file") |
| 42 |
if dry.replace('dndir', 'X') != real.replace('rdir', 'X'): |
| 43 |
test_fail(f"--mkpath dry-run output differs from the real run:\n" |
| 44 |
f" dry : {dry!r}\n real: {real!r}") |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
ex = SCRATCHDIR / 'ex' |
| 50 |
rmtree(ex) |
| 51 |
makepath(ex / 'a') |
| 52 |
makepath(ex / 'b') |
| 53 |
(ex / 'src').write_text("brand new content\n") |
| 54 |
for d in ('a', 'b'): |
| 55 |
(ex / d / 'dst').write_text("old\n") |
| 56 |
os.utime(ex / d / 'dst', (0, 0)) |
| 57 |
|
| 58 |
_, dry2 = itemize('--dry-run', str(ex / 'src'), str(ex / 'a' / 'dst')) |
| 59 |
_, real2 = itemize(str(ex / 'src'), str(ex / 'b' / 'dst')) |
| 60 |
if dry2 != real2: |
| 61 |
test_fail(f"file-to-file --dry-run misreports an existing destination:\n" |
| 62 |
f" dry : {dry2!r}\n real: {real2!r}") |