now allows recursive copies of non-writable directories (chris@maryland)
authorJim Bloom <bloom@ucbvax.Berkeley.EDU>
Thu, 10 Oct 1985 03:09:38 +0000 (19:09 -0800)
committerJim Bloom <bloom@ucbvax.Berkeley.EDU>
Thu, 10 Oct 1985 03:09:38 +0000 (19:09 -0800)
SCCS-vsn: bin/cp/cp.c 4.12

usr/src/bin/cp/cp.c

index 4cf4fc7..092302e 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cp.c        4.11 (Berkeley) %G%";
+static char *sccsid = "@(#)cp.c        4.12 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -93,18 +93,24 @@ copy(from, to)
                to = destname;
        }
        if (rflag && (stfrom.st_mode&S_IFMT) == S_IFDIR) {
                to = destname;
        }
        if (rflag && (stfrom.st_mode&S_IFMT) == S_IFDIR) {
+               int fixmode = 0;        /* cleanup mode after rcopy */
+
                (void) close(fold);
                if (stat(to, &stto) < 0) {
                (void) close(fold);
                if (stat(to, &stto) < 0) {
-                       if (mkdir(to, stfrom.st_mode & 07777) < 0) {
+                       if (mkdir(to, (stfrom.st_mode & 07777) | 0700) < 0) {
                                Perror(to);
                                return (1);
                        }
                                Perror(to);
                                return (1);
                        }
+                       fixmode = 1;
                } else if ((stto.st_mode&S_IFMT) != S_IFDIR) {
                        fprintf(stderr, "cp: %s: Not a directory.\n", to);
                        return (1);
                } else if (pflag)
                } else if ((stto.st_mode&S_IFMT) != S_IFDIR) {
                        fprintf(stderr, "cp: %s: Not a directory.\n", to);
                        return (1);
                } else if (pflag)
+                       fixmode = 1;
+               n = rcopy(from, to);
+               if (fixmode)
                        (void) chmod(to, stfrom.st_mode & 07777);
                        (void) chmod(to, stfrom.st_mode & 07777);
-               return (rcopy(from, to));
+               return (n);
        }
 
        if ((stfrom.st_mode&S_IFMT) == S_IFDIR)
        }
 
        if ((stfrom.st_mode&S_IFMT) == S_IFDIR)