]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
cp: fix -R recursion detection
authorKyle Evans <kevans@FreeBSD.org>
Wed, 6 Apr 2022 01:40:53 +0000 (20:40 -0500)
committerKyle Evans <kevans@FreeBSD.org>
Sun, 24 Apr 2022 03:51:28 +0000 (22:51 -0500)
commit587dacce01b34e67c297d185bf245a7649ed3cf3
treea0d1131362578c6e0f88ddc8f252d0ab0c5854c1
parent5237a02ba86b5957d10d87148bbc0efb3f2f6f82
cp: fix -R recursion detection

The correct logic is a lot simpler than the previous iteration.  We
record the base fts_name to avoid having to worry about whether we
needed the root symlink name or not (as applicable), then we can simply
shift all of that logic to after path translation to make it less
fragile.

If we're copying to DNE, then we'll have swapped out the NULL root_stat
pointer and then attempted to recurse on it.  The previously nonexistent
directory shouldn't exist at all in the new structure, so just back out
from that tree entirely and move on.

The tests have been amended to indicate our expectations better with
subdirectory recursion.  If we copy A to A/B, then we expect to copy
everything from A/B/* into A/B/A/B, with exception to the A that we
create in A/B.

Reviewed by: bapt
Sponsored by: Klara, Inc.

(cherry picked from commit f00f8b4fbd268a212687984e44daa3e0d0a16b87)
bin/cp/cp.c
bin/cp/tests/cp_test.sh