aboutsummaryrefslogtreecommitdiff
path: root/bin/cp
diff options
context:
space:
mode:
authorTim J. Robbins <tjr@FreeBSD.org>2002-06-13 15:48:36 +0000
committerTim J. Robbins <tjr@FreeBSD.org>2002-06-13 15:48:36 +0000
commitf9dc2a8b93fd1b074ba196889335a6aaa45b851d (patch)
tree44ebc494d8e4b64b09b7d4692196f036b35574d3 /bin/cp
parent560edda3666c5bc3f71a2aea8d5c061296c2066a (diff)
downloadsrc-f9dc2a8b93fd1b074ba196889335a6aaa45b851d.tar.gz
src-f9dc2a8b93fd1b074ba196889335a6aaa45b851d.zip
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
Notes
Notes: svn path=/head/; revision=98171
Diffstat (limited to 'bin/cp')
-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 e2c289a212c0..be20cbbd1993 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) {