The combination of -v and -i and the deny of a copy would cause the copy
authormartijn <martijn@openbsd.org>
Fri, 7 Sep 2018 07:11:16 +0000 (07:11 +0000)
committermartijn <martijn@openbsd.org>
Fri, 7 Sep 2018 07:11:16 +0000 (07:11 +0000)
still to be printed. This fixes that edge-case.

OK stsp@

bin/cp/cp.c
bin/cp/utils.c

index 532edbb..6e558e9 100644 (file)
@@ -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;
                }
        }
index c9d7198..5d4db72 100644 (file)
@@ -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);