git: be7839151cc9 - main - cp: Fix dead link case.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 10 May 2025 08:57:14 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=be7839151cc9e3dfc428933d5f2705b32cdf4b86
commit be7839151cc9e3dfc428933d5f2705b32cdf4b86
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-05-10 08:55:35 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-05-10 08:55:35 +0000
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: 82fc0d09e862
Sponsored by: Klara, Inc.
Reviewed by: allanjude, markj
Differential Revision: https://reviews.freebsd.org/D50257
---
bin/cp/cp.c | 2 +-
bin/cp/tests/cp_test.sh | 11 ++++++++---
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index f1cfde7e5008..a3c8d910639c 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -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;
/*
diff --git a/bin/cp/tests/cp_test.sh b/bin/cp/tests/cp_test.sh
index 6644588f1ce8..bfc4009580cb 100755
--- a/bin/cp/tests/cp_test.sh
+++ b/bin/cp/tests/cp_test.sh
@@ -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/baz
+ rm -f bar/foo bar/baz
+ ln -s $PWD/baz bar/foo
atf_check cp foo bar/
- atf_check cmp -s foo bar/foo
+ atf_check cmp -s foo baz
}
atf_test_case to_dirlink