aboutsummaryrefslogtreecommitdiff
path: root/bin/cp/tests
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2022-04-06 01:40:53 +0000
committerKyle Evans <kevans@FreeBSD.org>2022-04-24 03:51:28 +0000
commit587dacce01b34e67c297d185bf245a7649ed3cf3 (patch)
treea0d1131362578c6e0f88ddc8f252d0ab0c5854c1 /bin/cp/tests
parent5237a02ba86b5957d10d87148bbc0efb3f2f6f82 (diff)
downloadsrc-587dacce01b34e67c297d185bf245a7649ed3cf3.tar.gz
src-587dacce01b34e67c297d185bf245a7649ed3cf3.zip
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)
Diffstat (limited to 'bin/cp/tests')
-rwxr-xr-xbin/cp/tests/cp_test.sh15
1 files changed, 12 insertions, 3 deletions
diff --git a/bin/cp/tests/cp_test.sh b/bin/cp/tests/cp_test.sh
index adb6ea24d9e7..7362168d7303 100755
--- a/bin/cp/tests/cp_test.sh
+++ b/bin/cp/tests/cp_test.sh
@@ -95,16 +95,25 @@ matching_srctgt_contained_body()
# Let's do the same thing, except we'll try to recursively copy foo into
# one of its subdirectories.
mkdir foo
+ ln -s foo coo
echo "qux" > foo/bar
- mkdir foo/loo
mkdir foo/moo
- mkdir foo/roo
+ touch foo/moo/roo
cp foo/bar foo/zoo
atf_check cp -R foo foo/moo
+ atf_check cp -RH coo foo/moo
atf_check -o inline:"qux\n" cat foo/moo/foo/bar
+ atf_check -o inline:"qux\n" cat foo/moo/coo/bar
atf_check -o inline:"qux\n" cat foo/moo/foo/zoo
- atf_check -e not-empty -s not-exit:0 stat foo/moo/foo/moo
+ atf_check -o inline:"qux\n" cat foo/moo/coo/zoo
+
+ # We should have copied the contents of foo/moo before foo, coo started
+ # getting copied in.
+ atf_check -o not-empty stat foo/moo/foo/moo/roo
+ atf_check -o not-empty stat foo/moo/coo/moo/roo
+ atf_check -e not-empty -s not-exit:0 stat foo/moo/foo/moo/foo
+ atf_check -e not-empty -s not-exit:0 stat foo/moo/coo/moo/coo
}
atf_test_case matching_srctgt_link