From owner-freebsd-hackers Tue May 12 01:42:29 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id BAA28631 for freebsd-hackers-outgoing; Tue, 12 May 1998 01:42:29 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from xcf.berkeley.edu (scam.XCF.Berkeley.EDU [128.32.43.201]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id BAA28617 for ; Tue, 12 May 1998 01:42:25 -0700 (PDT) (envelope-from nordwick@scam.xcf.berkeley.edu) Received: (qmail 7873 invoked from network); 12 May 1998 08:43:42 -0000 Received: from ip107.san-francisco22.ca.pub-ip.psi.net (HELO scam.xcf.berkeley.edu) (38.28.60.107) by scam.xcf.berkeley.edu with SMTP; 12 May 1998 08:43:42 -0000 Message-ID: <355809C0.301AB313@scam.xcf.berkeley.edu> Date: Tue, 12 May 1998 01:35:12 -0700 From: Jason Nordwick X-Mailer: Mozilla 4.05 [en] (X11; I; FreeBSD 3.0-980222-SNAP i386) MIME-Version: 1.0 To: freebsd-hackers@FreeBSD.ORG Subject: cp Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I was looking into bin/5733 concerning cp and since this is my first attempt at fixing anything in the system, I though that I would see if it is an okay fix. The problem was that you could not recursively copy a directory structure where a non terminal directory was read-only. Appended is the diff to cp.c Also appended is a diff to utils.c that fixes a small non-problem; it used to report chown error, but was really a chmod error. Finally a questions: shouldn't the return values in mastercmp() be changed if it is to fit the comments above it? Here is that code segment: /* * mastercmp -- * The comparison function for the copy order. The order is to copy * non-directory files before directory files. The reason for this * is because files tend to be in the same cylinder group as their * parent directory, whereas directories tend not to be. Copying the * files first reduces seeking. */ int mastercmp(a, b) const FTSENT **a, **b; { int a_info, b_info; a_info = (*a)->fts_info; if (a_info == FTS_ERR || a_info == FTS_NS || a_info == FTS_DNR) return (0); b_info = (*b)->fts_info; if (b_info == FTS_ERR || b_info == FTS_NS || b_info == FTS_DNR) return (0); if (a_info == FTS_D) return (-1); if (b_info == FTS_D) return (1); return (0); } And here are the two diffs I said I would have: --- cp.c.orig Wed May 6 04:13:48 1998 +++ cp.c Tue May 12 01:23:46 1998 @@ -249,7 +249,7 @@ struct stat to_stat; FTS *ftsp; FTSENT *curr; - int base = 0, dne, nlen, rval; + int base = 0, dne, nlen, rval, postdir = 0; char *p, *target_mid; if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL) @@ -266,8 +266,9 @@ warnx("%s: directory causes a cycle", curr->fts_path); rval = 1; continue; - case FTS_DP: /* Ignore, continue. */ - continue; + case FTS_DP: + postdir = 1; + break; } /* @@ -324,6 +325,14 @@ STRIP_TRAILING_SLASH(to); } + if (postdir) { + if (chmod(to.p_path, curr->fts_statp->st_mode) == -1) + warnx("%s just created, but now missing?", + to.p_path); + postdir = 0; + continue; + } + /* Not an error but need to remember it happened */ if (stat(to.p_path, &to_stat) == -1) dne = 1; @@ -384,9 +393,10 @@ */ if (pflag && setfile(curr->fts_statp, 0)) rval = 1; - else if (dne) - (void)chmod(to.p_path, - curr->fts_statp->st_mode); + /* + * we used to chmod new directories here, but + * now we do it on the way back up the tree. + */ break; case S_IFBLK: case S_IFCHR: --- utils.c.orig Tue May 12 01:24:52 1998 +++ utils.c Tue May 12 01:25:19 1998 @@ -290,7 +290,7 @@ fs->st_mode &= ~(S_ISUID | S_ISGID); } if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) { - warn("chown: %s", to.p_path); + warn("chmod: %s", to.p_path); rval = 1; } -- 4.4 > 95 http://www.xcf.berkeley.edu To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message