summaryrefslogtreecommitdiff
path: root/bin/cp/utils.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1999-05-06 17:19:48 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1999-05-06 17:19:48 +0000
commit38f40a727c936905a9e791c6d9df12b8d51fdbae (patch)
tree2cc084a6587d9274e383d7baba926077852b7d6e /bin/cp/utils.c
parentb98c3f75685de38f4cd5cc7b1803bcf1eaa2fc0c (diff)
"cp -f" should unlink the destination before copying. Similar to
a patch from FreeBSD (but this is simpler). Closes PR #821
Diffstat (limited to 'bin/cp/utils.c')
-rw-r--r--bin/cp/utils.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index 679b63494db..5d7f9b37b3a 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: utils.c,v 1.13 1998/09/26 21:53:16 deraadt Exp $ */
+/* $OpenBSD: utils.c,v 1.14 1999/05/06 17:19:47 millert Exp $ */
/* $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
#else
-static char rcsid[] = "$OpenBSD: utils.c,v 1.13 1998/09/26 21:53:16 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: utils.c,v 1.14 1999/05/06 17:19:47 millert Exp $";
#endif
#endif /* not lint */
@@ -78,6 +78,13 @@ copy_file(entp, dne)
fs = entp->fts_statp;
/*
+ * In -f (force) mode, we always unlink the destination first
+ * if it exists. Note that -i and -f are mututally exclusive.
+ */
+ if (!dne && fflag)
+ (void)unlink(to.p_path);
+
+ /*
* If the file exists and we're interactive, verify with the user.
* If the file DNE, set the mode to be the from file, minus setuid
* bits, modified by the umask; arguably wrong, but it makes copying
@@ -85,7 +92,7 @@ copy_file(entp, dne)
* other choice is 666 or'ed with the execute bits on the from file
* modified by the umask.)
*/
- if (!dne) {
+ if (!dne && !fflag) {
if (iflag) {
(void)fprintf(stderr, "overwrite %s? ", to.p_path);
checkch = ch = getchar();