cp: Fix dead link case.

The test case was a) not doing what I intended it to do and b) missing
a third possible configuration.  Fix the test case, and fix the code
by not setting the beneath flag (which restricts operations to the
destination tree) unless we are recursing.

Fixes:		82fc0d09e8
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude, markj
Differential Revision:	https://reviews.freebsd.org/D50257
This commit is contained in:
Dag-Erling Smørgrav 2025-05-10 10:55:35 +02:00
parent a4f6317bb6
commit be7839151c
2 changed files with 9 additions and 4 deletions

View file

@ -267,7 +267,7 @@ copy(char *argv[], enum op type, int fts_options, struct stat *root_stat)
char *recpath = NULL;
int atflags, dne, badcp, len, rval;
mode_t mask, mode;
bool beneath = type != FILE_TO_FILE;
bool beneath = Rflag && type != FILE_TO_FILE;
bool skipdp = false;
/*

View file

@ -479,10 +479,15 @@ to_deadlink_append_body()
mkdir bar
ln -s baz bar/foo
atf_check cp foo bar
atf_check cmp -s foo bar/foo
rm -f bar/foo
atf_check cmp -s foo bar/baz
rm -f bar/foo bar/baz
ln -s baz bar/foo
atf_check cp foo bar/
atf_check cmp -s foo bar/foo
atf_check cmp -s foo bar/baz
rm -f bar/foo bar/baz
ln -s $PWD/baz bar/foo
atf_check cp foo bar/
atf_check cmp -s foo baz
}
atf_test_case to_dirlink