| 1 |
|
| 2 |
"""Coverage of --temp-dir (-T) at depth and across directory boundaries. |
| 3 |
|
| 4 |
--temp-dir tells the receiver to create its scratch/temp copies in DIR rather |
| 5 |
than in the destination directory, then rename the finished file into place. |
| 6 |
That rename crosses from the temp directory to a destination directory several |
| 7 |
levels deep -- exactly the two-directory operation the path-resolution |
| 8 |
restructure rewrites -- so it must be guarded at depth with the temp dir kept |
| 9 |
OUTSIDE the destination tree. |
| 10 |
|
| 11 |
Asserts: |
| 12 |
* a transfer with --temp-dir pointing outside the dest tree reproduces the |
| 13 |
source byte-for-byte at every level; |
| 14 |
* no temp/scratch files are left behind in the temp dir or the dest tree; |
| 15 |
* a non-existent --temp-dir makes the receiver fail (so we know the option |
| 16 |
is actually consulted, not silently ignored). |
| 17 |
""" |
| 18 |
|
| 19 |
import os |
| 20 |
|
| 21 |
from rsyncfns import ( |
| 22 |
FROMDIR, SCRATCHDIR, TODIR, |
| 23 |
assert_same, make_tree, rmtree, run_rsync, test_fail, walk_files, |
| 24 |
) |
| 25 |
|
| 26 |
src = FROMDIR |
| 27 |
tmp = SCRATCHDIR / 'scratch-temp' |
| 28 |
rmtree(src) |
| 29 |
rmtree(TODIR) |
| 30 |
rmtree(tmp) |
| 31 |
tmp.mkdir() |
| 32 |
|
| 33 |
make_tree(src, depth=3, data=True) |
| 34 |
rels = [p.relative_to(src) for p in walk_files(src)] |
| 35 |
|
| 36 |
|
| 37 |
run_rsync('-a', f'--temp-dir={tmp}', f'{src}/', f'{TODIR}/') |
| 38 |
|
| 39 |
for rel in rels: |
| 40 |
assert_same(TODIR / rel, src / rel, label=f'temp-dir {rel}') |
| 41 |
|
| 42 |
|
| 43 |
leftover = sorted(p for p in tmp.rglob('*')) |
| 44 |
if leftover: |
| 45 |
test_fail(f"--temp-dir left scratch files behind: {leftover}") |
| 46 |
|
| 47 |
|
| 48 |
strays = [p for p in TODIR.rglob('.*') if p.is_file()] |
| 49 |
if strays: |
| 50 |
test_fail(f"dest tree contains stray temp files: {strays}") |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
rmtree(TODIR) |
| 55 |
proc = run_rsync('-a', f'--temp-dir={SCRATCHDIR}/does-not-exist', |
| 56 |
f'{src}/', f'{TODIR}/', check=False) |
| 57 |
if proc.returncode == 0: |
| 58 |
test_fail("--temp-dir pointing at a missing directory unexpectedly " |
| 59 |
"succeeded") |
| 60 |
|
| 61 |
print("temp-dir: cross-dir rename at depth verified; missing temp dir fails") |