Files
rsync/testsuite/dirs_test.py
Andrew Tridgell 0d546ee3b4 testsuite: structure / recursion / link coverage at depth
Cover the structure and link options at >=3 levels and across directories,
asserting each option's specific effect:

  links            -l keeps a symlink, -L dereferences it, -k follows a
                   directory symlink -- all on a symlink several levels deep.
  dirs             -d copies the top layer (file + empty dir) without recursing.
  prune-empty-dirs -m drops empty chains and chains emptied by an exclude,
                   keeps populated ones.
  hardlinks-deep   -H preserves a hard link whose names live in different
                   directories at depth; without -H they become separate inodes.
  delete-deep      --delete removes a deep extraneous file/subtree; the four
                   delete-timing variants agree; --max-delete caps deletions;
                   --existing / --ignore-existing select/skip correctly.
  relative-implied -R mirrors an implied directory's mode at depth;
                   --no-implied-dirs does not (proto 30+).

Green on master and under --protocol=29/30 (the --no-implied-dirs sub-case is
gated to protocol >= 30, where multi-component sender paths are accepted).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 12:31:52 +10:00

34 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Coverage of -d / --dirs: transfer directories without recursing into them.
-d copies the entries directly named (or directly inside a trailing-slash
source): regular files at the top level are copied, and a top-level directory
is created as an empty directory -- its contents are NOT transferred. Verify
that on a tree that is several levels deep, only the top layer materialises.
"""
from rsyncfns import (
FROMDIR, TODIR,
assert_same, make_tree, rmtree, run_rsync, test_fail,
)
src = FROMDIR
rmtree(src)
rmtree(TODIR)
make_tree(src, depth=3) # f0 at root; d1/{f1, d2/{f2, d3/f3}}
run_rsync('-d', f'{src}/', f'{TODIR}/')
# The top-level file is copied.
assert_same(TODIR / 'f0', src / 'f0', label='-d top-level file')
# The top-level directory is created...
if not (TODIR / 'd1').is_dir():
test_fail("-d did not create the top-level directory")
# ...but NOT recursed into.
if (TODIR / 'd1' / 'f1').exists():
test_fail("-d recursed into a directory (f1 should not exist)")
if list((TODIR / 'd1').iterdir()):
test_fail("-d populated the directory; it should be empty")
print("dirs: -d copies the top layer without recursing")