From: martijn Date: Fri, 7 Sep 2018 07:17:14 +0000 (+0000) Subject: Also verify a overwrite for the copy of a fifo, link and device node. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=1a4428c6c41dde310c7c961686d6e862ca8f32cc;p=openbsd Also verify a overwrite for the copy of a fifo, link and device node. OK stsp@ --- diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 6e558e99588..7df43582f5a 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -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) diff --git a/bin/cp/utils.c b/bin/cp/utils.c index 8d03cc93c92..1b431f4944e 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -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);