summaryrefslogtreecommitdiffstats
path: root/bin/cp/cp.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-06-13 15:48:36 +0000
committertjr <tjr@FreeBSD.org>2002-06-13 15:48:36 +0000
commit041d0fbbd905c0e30b4155f0bbdfbafd459b50d8 (patch)
tree44ebc494d8e4b64b09b7d4692196f036b35574d3 /bin/cp/cp.c
parent14714108891719cd4af97afba8c20ed7b9f5a0f4 (diff)
downloadFreeBSD-src-041d0fbbd905c0e30b4155f0bbdfbafd459b50d8.zip
FreeBSD-src-041d0fbbd905c0e30b4155f0bbdfbafd459b50d8.tar.gz
When -R is not specified, fail to copy the contents of dangling symlinks
instead of making a copy of the link itself (SUSv3) Obtained from: NetBSD
Diffstat (limited to 'bin/cp/cp.c')
-rw-r--r--bin/cp/cp.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index e2c289a..be20cbb 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -167,7 +167,7 @@ main(int argc, char *argv[])
}
} else {
fts_options &= ~FTS_PHYSICAL;
- fts_options |= FTS_LOGICAL;
+ fts_options |= FTS_LOGICAL | FTS_COMFOLLOW;
}
/* Save the target base in "to". */
@@ -397,8 +397,16 @@ copy(char *argv[], enum op type, int fts_options)
switch (curr->fts_statp->st_mode & S_IFMT) {
case S_IFLNK:
- if (copy_link(curr, !dne))
- badcp = rval = 1;
+ /* Catch special case of a non-dangling symlink */
+ if ((fts_options & FTS_LOGICAL) ||
+ ((fts_options & FTS_COMFOLLOW) &&
+ curr->fts_level == 0)) {
+ if (copy_file(curr, dne))
+ badcp = rval = 1;
+ } else {
+ if (copy_link(curr, !dne))
+ badcp = rval = 1;
+ }
break;
case S_IFDIR:
if (!Rflag && !rflag) {
OpenPOWER on IntegriCloud