diff options
author | Stefan Sperling <stsp@cvs.openbsd.org> | 2018-09-07 11:01:23 +0000 |
---|---|---|
committer | Stefan Sperling <stsp@cvs.openbsd.org> | 2018-09-07 11:01:23 +0000 |
commit | 799bc7aae7a1101e64bad16cee959a18f4aa60fc (patch) | |
tree | cc3e82112f08674233569fadaca4740a5201126c | |
parent | 20a9166c4140d10013dc6e9b3b933d6c5726f48f (diff) |
Backout recent cp(1) changes; they broke texlive's mktexlsr(1)
-rw-r--r-- | bin/cp/cp.c | 30 | ||||
-rw-r--r-- | bin/cp/utils.c | 53 |
2 files changed, 30 insertions, 53 deletions
diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 23f4245d59b..282defd171f 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cp.c,v 1.49 2018/09/07 07:44:15 martijn Exp $ */ +/* $OpenBSD: cp.c,v 1.50 2018/09/07 11:01:22 stsp 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, cval, nlen, rval; + int base, nlen, rval; char *p, *target_mid; base = 0; @@ -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 ((cval = copy_link(curr, !fts_dne(curr))) == 1) + if (copy_link(curr, !fts_dne(curr))) rval = 1; - if (!cval && vflag) + else if (vflag) (void)fprintf(stdout, "%s -> %s\n", curr->fts_path, to.p_path); break; @@ -430,40 +430,36 @@ copy(char *argv[], enum op type, int fts_options) case S_IFBLK: case S_IFCHR: if (Rflag) { - if ((cval = copy_special(curr->fts_statp, - !fts_dne(curr))) == 1) + if (copy_special(curr->fts_statp, + !fts_dne(curr))) rval = 1; } else - if ((cval = copy_file(curr, !fts_dne(curr))) == 1) + if (copy_file(curr, fts_dne(curr))) rval = 1; - if (!cval && vflag) + if (!rval && vflag) (void)fprintf(stdout, "%s -> %s\n", curr->fts_path, to.p_path); - cval = 0; break; case S_IFIFO: if (Rflag) { - if ((cval = copy_fifo(curr->fts_statp, - !fts_dne(curr))) == 1) + if (copy_fifo(curr->fts_statp, !fts_dne(curr))) rval = 1; } else - if ((cval = copy_file(curr, !fts_dne(curr))) == 1) + if (copy_file(curr, fts_dne(curr))) rval = 1; - if (!cval && vflag) + if (!rval && 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 ((cval = copy_file(curr, !fts_dne(curr))) == 1) + if (copy_file(curr, fts_dne(curr))) rval = 1; - if (!cval && vflag) + else if (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 fd2af24ba1e..ef4d1f1e2b6 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utils.c,v 1.44 2018/09/07 07:44:15 martijn Exp $ */ +/* $OpenBSD: utils.c,v 1.45 2018/09/07 11:01:22 stsp Exp $ */ /* $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $ */ /*- @@ -47,15 +47,13 @@ #include "extern.h" -int copy_overwrite(void); - int -copy_file(FTSENT *entp, int exists) +copy_file(FTSENT *entp, int dne) { static char *buf; static char *zeroes; struct stat to_stat, *fs; - int from_fd, rcount, rval, to_fd, wcount; + int ch, checkch, from_fd, rcount, rval, to_fd, wcount; #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED char *p; #endif @@ -82,21 +80,28 @@ copy_file(FTSENT *entp, int exists) * In -f (force) mode, we always unlink the destination first * if it exists. Note that -i and -f are mutually exclusive. */ - if (exists && fflag) + if (!dne && fflag) (void)unlink(to.p_path); /* + * If the file exists and we're interactive, verify with the user. * If the file DNE, set the mode to be the from file, minus setuid * bits, modified by the umask; arguably wrong, but it makes copying * executables work right and it's been that way forever. (The * other choice is 666 or'ed with the execute bits on the from file * modified by the umask.) */ - if (exists && !fflag) { - if (!copy_overwrite()) { - (void)close(from_fd); - return 2; - } + if (!dne && !fflag) { + if (iflag) { + (void)fprintf(stderr, "overwrite %s? ", to.p_path); + checkch = ch = getchar(); + while (ch != '\n' && ch != EOF) + ch = getchar(); + if (checkch != 'y' && checkch != 'Y') { + (void)close(from_fd); + return (0); + } + } to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0); } else to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT, @@ -174,7 +179,7 @@ copy_file(FTSENT *entp, int exists) */ #define RETAINBITS \ (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) - if (!pflag && !exists && + if (!pflag && dne && fs->st_mode & (S_ISUID | S_ISGID) && fs->st_uid == myuid) { if (fstat(to_fd, &to_stat)) { warn("%s", to.p_path); @@ -199,8 +204,6 @@ 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); @@ -220,8 +223,6 @@ 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); @@ -236,8 +237,6 @@ 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); @@ -249,24 +248,6 @@ copy_special(struct stat *from_stat, int exists) return (pflag ? setfile(from_stat, -1) : 0); } -/* - * If the file exists and we're interactive, verify with the user. - */ -int -copy_overwrite(void) -{ - int ch, checkch; - - if (iflag) { - (void)fprintf(stderr, "overwrite %s? ", to.p_path); - checkch = ch = getchar(); - while (ch != '\n' && ch != EOF) - ch = getchar(); - if (checkch != 'y' && checkch != 'Y') - return (0); - } - return 1; -} int setfile(struct stat *fs, int fd) |