From ac2f5a9e421e6dd5b5b787db1538def0fa1749f4 Mon Sep 17 00:00:00 2001 From: martijn Date: Fri, 7 Sep 2018 07:11:16 +0000 Subject: [PATCH] The combination of -v and -i and the deny of a copy would cause the copy still to be printed. This fixes that edge-case. OK stsp@ --- bin/cp/cp.c | 19 +++++++++++-------- bin/cp/utils.c | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 532edbb5ba7..6e558e99588 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cp.c,v 1.46 2017/06/27 21:49:47 tedu Exp $ */ +/* $OpenBSD: cp.c,v 1.47 2018/09/07 07:11:16 martijn Exp $ */ /* $NetBSD: cp.c,v 1.14 1995/09/07 06:14:51 jtc Exp $ */ /* @@ -264,7 +264,7 @@ copy(char *argv[], enum op type, int fts_options) struct stat to_stat; FTS *ftsp; FTSENT *curr; - int base, nlen, rval; + int base, cval, nlen, rval; char *p, *target_mid; base = 0; @@ -434,32 +434,35 @@ copy(char *argv[], enum op type, int fts_options) !fts_dne(curr))) rval = 1; } else - if (copy_file(curr, fts_dne(curr))) + if ((cval = copy_file(curr, fts_dne(curr))) == 1) rval = 1; - if (!rval && vflag) + if (!cval && vflag) (void)fprintf(stdout, "%s -> %s\n", curr->fts_path, to.p_path); + cval = 0; break; case S_IFIFO: if (Rflag) { if (copy_fifo(curr->fts_statp, !fts_dne(curr))) rval = 1; } else - if (copy_file(curr, fts_dne(curr))) + if ((cval = copy_file(curr, fts_dne(curr))) == 1) rval = 1; - if (!rval && vflag) + if (!cval && vflag) (void)fprintf(stdout, "%s -> %s\n", curr->fts_path, to.p_path); + cval = 0; break; case S_IFSOCK: warnc(EOPNOTSUPP, "%s", curr->fts_path); break; default: - if (copy_file(curr, fts_dne(curr))) + if ((cval = copy_file(curr, fts_dne(curr))) == 1) rval = 1; - else if (vflag) + if (!cval && vflag) (void)fprintf(stdout, "%s -> %s\n", curr->fts_path, to.p_path); + cval = 0; break; } } diff --git a/bin/cp/utils.c b/bin/cp/utils.c index c9d71986842..5d4db72ba10 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utils.c,v 1.40 2017/06/27 21:43:46 tedu Exp $ */ +/* $OpenBSD: utils.c,v 1.41 2018/09/07 07:11:16 martijn Exp $ */ /* $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $ */ /*- @@ -99,7 +99,7 @@ copy_file(FTSENT *entp, int dne) ch = getchar(); if (checkch != 'y' && checkch != 'Y') { (void)close(from_fd); - return (0); + return (2); } } to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0); -- 2.20.1