Also verify a overwrite for the copy of a fifo, link and device node.
authormartijn <martijn@openbsd.org>
Fri, 7 Sep 2018 07:17:14 +0000 (07:17 +0000)
committermartijn <martijn@openbsd.org>
Fri, 7 Sep 2018 07:17:14 +0000 (07:17 +0000)
OK stsp@

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

index 6e558e9..7df4358 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cp.c,v 1.47 2018/09/07 07:11:16 martijn Exp $ */
+/*     $OpenBSD: cp.c,v 1.48 2018/09/07 07:17:14 martijn Exp $ */
 /*     $NetBSD: cp.c,v 1.14 1995/09/07 06:14:51 jtc Exp $      */
 
 /*
@@ -395,9 +395,9 @@ copy(char *argv[], enum op type, int fts_options)
 
                switch (curr->fts_statp->st_mode & S_IFMT) {
                case S_IFLNK:
-                       if (copy_link(curr, !fts_dne(curr)))
+                       if ((cval = copy_link(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);
                        break;
@@ -430,8 +430,8 @@ copy(char *argv[], enum op type, int fts_options)
                case S_IFBLK:
                case S_IFCHR:
                        if (Rflag) {
-                               if (copy_special(curr->fts_statp,
-                                   !fts_dne(curr)))
+                               if ((cval = copy_special(curr->fts_statp,
+                                   !fts_dne(curr))) == 1)
                                        rval = 1;
                        } else
                                if ((cval = copy_file(curr, fts_dne(curr))) == 1)
@@ -443,7 +443,8 @@ copy(char *argv[], enum op type, int fts_options)
                        break;
                case S_IFIFO:
                        if (Rflag) {
-                               if (copy_fifo(curr->fts_statp, !fts_dne(curr)))
+                               if ((cval = copy_fifo(curr->fts_statp,
+                                   !fts_dne(curr))) == 1)
                                        rval = 1;
                        } else
                                if ((cval = copy_file(curr, fts_dne(curr))) == 1)
index 8d03cc9..1b431f4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: utils.c,v 1.42 2018/09/07 07:14:25 martijn Exp $      */
+/*     $OpenBSD: utils.c,v 1.43 2018/09/07 07:17:14 martijn Exp $      */
 /*     $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $    */
 
 /*-
@@ -199,6 +199,8 @@ copy_link(FTSENT *p, int exists)
        int len;
        char name[PATH_MAX];
 
+       if (exists && !copy_overwrite())
+               return (2);
        if ((len = readlink(p->fts_path, name, sizeof(name)-1)) == -1) {
                warn("readlink: %s", p->fts_path);
                return (1);
@@ -218,6 +220,8 @@ copy_link(FTSENT *p, int exists)
 int
 copy_fifo(struct stat *from_stat, int exists)
 {
+       if (exists && !copy_overwrite())
+               return (2);
        if (exists && unlink(to.p_path)) {
                warn("unlink: %s", to.p_path);
                return (1);
@@ -232,6 +236,8 @@ copy_fifo(struct stat *from_stat, int exists)
 int
 copy_special(struct stat *from_stat, int exists)
 {
+       if (exists && !copy_overwrite())
+               return (2);
        if (exists && unlink(to.p_path)) {
                warn("unlink: %s", to.p_path);
                return (1);