cp: fix -R with links
The traversal was previously not properly honoring -H/-L/-P. Notably, we should not have been resolving symlinks encountered during traversal when either -H or -P are specified. Sponsored by: Klara, Inc. Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D34063
This commit is contained in:
@@ -43,6 +43,21 @@ basic_body()
|
||||
check_size baz 4
|
||||
}
|
||||
|
||||
atf_test_case basic_symlink
|
||||
basic_symlink_body()
|
||||
{
|
||||
echo "foo" > bar
|
||||
ln -s bar baz
|
||||
|
||||
atf_check cp baz foo
|
||||
atf_check test '!' -L foo
|
||||
|
||||
atf_check -e inline:"cp: baz and baz are identical (not copied).\n" \
|
||||
-s exit:1 cp baz baz
|
||||
atf_check -e inline:"cp: bar and baz are identical (not copied).\n" \
|
||||
-s exit:1 cp baz bar
|
||||
}
|
||||
|
||||
atf_test_case chrdev
|
||||
chrdev_body()
|
||||
{
|
||||
@@ -130,12 +145,61 @@ matching_srctgt_nonexistent_body()
|
||||
atf_check -e not-empty -s not-exit:0 stat foo/dne/foo
|
||||
}
|
||||
|
||||
recursive_link_setup()
|
||||
{
|
||||
extra_cpflag=$1
|
||||
|
||||
mkdir -p foo/bar
|
||||
ln -s bar foo/baz
|
||||
|
||||
mkdir foo-mirror
|
||||
eval "cp -R $extra_cpflag foo foo-mirror"
|
||||
}
|
||||
|
||||
atf_test_case recursive_link_dflt
|
||||
recursive_link_dflt_body()
|
||||
{
|
||||
recursive_link_setup
|
||||
|
||||
# -P is the default, so this should work and preserve the link.
|
||||
atf_check cp -R foo foo-mirror
|
||||
atf_check test -L foo-mirror/foo/baz
|
||||
}
|
||||
|
||||
atf_test_case recursive_link_Hflag
|
||||
recursive_link_Hflag_body()
|
||||
{
|
||||
recursive_link_setup
|
||||
|
||||
# -H will not follow either, so this should also work and preserve the
|
||||
# link.
|
||||
atf_check cp -RH foo foo-mirror
|
||||
atf_check test -L foo-mirror/foo/baz
|
||||
}
|
||||
|
||||
atf_test_case recursive_link_Lflag
|
||||
recursive_link_Lflag_body()
|
||||
{
|
||||
recursive_link_setup -L
|
||||
|
||||
# -L will work, but foo/baz ends up expanded to a directory.
|
||||
atf_check test -d foo-mirror/foo/baz -a \
|
||||
'(' ! -L foo-mirror/foo/baz ')'
|
||||
atf_check cp -RL foo foo-mirror
|
||||
atf_check test -d foo-mirror/foo/baz -a \
|
||||
'(' ! -L foo-mirror/foo/baz ')'
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case basic
|
||||
atf_add_test_case basic_symlink
|
||||
atf_add_test_case chrdev
|
||||
atf_add_test_case matching_srctgt
|
||||
atf_add_test_case matching_srctgt_contained
|
||||
atf_add_test_case matching_srctgt_link
|
||||
atf_add_test_case matching_srctgt_nonexistent
|
||||
atf_add_test_case recursive_link_dflt
|
||||
atf_add_test_case recursive_link_Hflag
|
||||
atf_add_test_case recursive_link_Lflag
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user