From 9d3fe418801a25c3c0be6e919a641d3f2a35e512 Mon Sep 17 00:00:00 2001 From: markj Date: Sun, 27 Jan 2013 05:59:28 +0000 Subject: Return with an error from copy_link(), copy_fifo() and copy_special() if the -n option is specified and the destination file exists. PR: bin/174489 Approved by: rstone (co-mentor) MFC after: 2 weeks --- bin/cp/utils.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'bin') diff --git a/bin/cp/utils.c b/bin/cp/utils.c index aa424f8..ad9695c 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -266,6 +266,11 @@ copy_link(const FTSENT *p, int exists) int len; char llink[PATH_MAX]; + if (exists && nflag) { + if (vflag) + printf("%s not overwritten\n", to.p_path); + return (1); + } if ((len = readlink(p->fts_path, llink, sizeof(llink) - 1)) == -1) { warn("readlink: %s", p->fts_path); return (1); @@ -285,6 +290,12 @@ copy_link(const FTSENT *p, int exists) int copy_fifo(struct stat *from_stat, int exists) { + + if (exists && nflag) { + if (vflag) + printf("%s not overwritten\n", to.p_path); + return (1); + } if (exists && unlink(to.p_path)) { warn("unlink: %s", to.p_path); return (1); @@ -299,6 +310,12 @@ copy_fifo(struct stat *from_stat, int exists) int copy_special(struct stat *from_stat, int exists) { + + if (exists && nflag) { + if (vflag) + printf("%s not overwritten\n", to.p_path); + return (1); + } if (exists && unlink(to.p_path)) { warn("unlink: %s", to.p_path); return (1); -- cgit v1.1