summaryrefslogtreecommitdiff
path: root/bin
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
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')
-rw-r--r--bin/cp/cp.c8
-rw-r--r--bin/cp/extern.h4
-rw-r--r--bin/cp/utils.c13
3 files changed, 17 insertions, 8 deletions
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index 86bd676da14..66358812598 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cp.c,v 1.12 1998/07/03 16:43:56 csapuntz Exp $ */
+/* $OpenBSD: cp.c,v 1.13 1999/05/06 17:19:45 millert Exp $ */
/* $NetBSD: cp.c,v 1.14 1995/09/07 06:14:51 jtc Exp $ */
/*
@@ -47,7 +47,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95";
#else
-static char rcsid[] = "$OpenBSD: cp.c,v 1.12 1998/07/03 16:43:56 csapuntz Exp $";
+static char rcsid[] = "$OpenBSD: cp.c,v 1.13 1999/05/06 17:19:45 millert Exp $";
#endif
#endif /* not lint */
@@ -91,7 +91,7 @@ static char rcsid[] = "$OpenBSD: cp.c,v 1.12 1998/07/03 16:43:56 csapuntz Exp $"
PATH_T to = { to.p_path, "" };
uid_t myuid;
-int Rflag, iflag, pflag, rflag;
+int Rflag, fflag, iflag, pflag, rflag;
int myumask;
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
@@ -129,10 +129,12 @@ main(argc, argv)
Rflag = 1;
break;
case 'f':
+ fflag = 1;
iflag = 0;
break;
case 'i':
iflag = isatty(fileno(stdin));
+ fflag = 0;
break;
case 'p':
pflag = 1;
diff --git a/bin/cp/extern.h b/bin/cp/extern.h
index c1fef5d086d..64de7e4bd86 100644
--- a/bin/cp/extern.h
+++ b/bin/cp/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.6 1997/11/08 23:17:12 todd Exp $ */
+/* $OpenBSD: extern.h,v 1.7 1999/05/06 17:19:46 millert Exp $ */
/* $NetBSD: extern.h,v 1.3 1995/03/21 09:02:16 cgd Exp $ */
/*-
@@ -44,7 +44,7 @@ typedef struct {
extern PATH_T to;
extern uid_t myuid;
-extern int iflag, pflag, myumask;
+extern int fflag, iflag, pflag, myumask;
#include <sys/cdefs.h>
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();