Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 May 1998 01:35:12 -0700
From:      Jason Nordwick <nordwick@scam.xcf.berkeley.edu>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   cp
Message-ID:  <355809C0.301AB313@scam.xcf.berkeley.edu>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?355809C0.301AB313>