CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Fri May 22 14:54:30 UTC 2020 Modified Files: src/bin/cp: cp.c Log Message: fix reversed test. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.61 src/bin/cp/cp.c:1.62 --- src/bin/cp/cp.c:1.61 Sun May 17 19:34:11 2020 +++ src/bin/cp/cp.c Fri May 22 10:54:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.61 2020/05/17 23:34:11 christos Exp $ */ +/* $NetBSD: cp.c,v 1.62 2020/05/22 14:54:30 christos Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: cp.c,v 1.61 2020/05/17 23:34:11 christos Exp $"); +__RCSID("$NetBSD: cp.c,v 1.62 2020/05/22 14:54:30 christos Exp $"); #endif #endif /* not lint */ @@ -517,7 +517,7 @@ copy(char *argv[], enum op type, int fts this_failed = any_failed = 1; #endif } -if (this_failed && (dne = popdne())) +if (!this_failed && (dne = popdne())) (void)chmod(to.p_path, curr->fts_statp->st_mode); }
CVS commit: src/bin/cp
Module Name:src Committed By: gutteridge Date: Sun Dec 23 01:29:23 UTC 2018 Modified Files: src/bin/cp: cp.1 Log Message: Clarify a sentence about the error handling of cp(1)'s -p option. Addresses PR bin/40336. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.45 src/bin/cp/cp.1:1.46 --- src/bin/cp/cp.1:1.45 Thu Aug 11 00:17:23 2016 +++ src/bin/cp/cp.1 Sun Dec 23 01:29:23 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.45 2016/08/11 00:17:23 sevan Exp $ +.\" $NetBSD: cp.1,v 1.46 2018/12/23 01:29:23 gutteridge Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd August 11, 2016 +.Dd December 22, 2018 .Dt CP 1 .Os .Sh NAME @@ -120,8 +120,9 @@ to preserve in the copy as many of the m file flags, file mode, user ID, group ID, and extended attributes, as allowed by permissions. .Pp -If the user ID and group ID cannot be preserved, no error message -is displayed and the exit value is not altered. +If the user ID and group ID cannot be preserved due to insufficient +permissions, no error message is displayed and the exit value is not +altered. .Pp If the source file has its set user ID bit on and the user ID cannot be preserved, the set user ID bit is not preserved
CVS commit: src/bin/cp
Module Name:src Committed By: darcy Date: Tue Jul 17 13:04:58 UTC 2018 Modified Files: src/bin/cp: utils.c Log Message: Re-order the code to short circuit all the opens and closes if linking. Discussed on tech-userlevel and agreed to by christos@. Testing suggests an order of magnitude improvement when linking. To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.45 src/bin/cp/utils.c:1.46 --- src/bin/cp/utils.c:1.45 Mon Feb 29 04:22:21 2016 +++ src/bin/cp/utils.c Tue Jul 17 13:04:58 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.45 2016/02/29 04:22:21 mrg Exp $ */ +/* $NetBSD: utils.c,v 1.46 2018/07/17 13:04:58 darcy Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.45 2016/02/29 04:22:21 mrg Exp $"); +__RCSID("$NetBSD: utils.c,v 1.46 2018/07/17 13:04:58 darcy Exp $"); #endif #endif /* not lint */ @@ -99,7 +99,17 @@ copy_file(FTSENT *entp, int dne) int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount; char *p; off_t ptotal = 0; - + + /* if hard linking then simply link and return */ + if (lflag) { + (void)unlink(to.p_path); + if (link(entp->fts_path, to.p_path)) { + warn("%s", to.p_path); + return (1); + } + return (0); + } + if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) { warn("%s", entp->fts_path); return (1); @@ -164,18 +174,6 @@ copy_file(FTSENT *entp, int dne) rval = 0; - /* if hard linking then simply close the open fds, link and return */ - if (lflag) { - (void)close(from_fd); - (void)close(to_fd); - (void)unlink(to.p_path); - if (link(entp->fts_path, to.p_path)) { - warn("%s", to.p_path); - return (1); - } - return (0); - } - /* * There's no reason to do anything other than close the file * now if it's empty, so let's not bother.
CVS commit: src/bin/cp
Module Name:src Committed By: sevan Date: Thu Aug 11 00:17:23 UTC 2016 Modified Files: src/bin/cp: cp.1 Log Message: Document the version cp first appeared. Bump date. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.44 src/bin/cp/cp.1:1.45 --- src/bin/cp/cp.1:1.44 Sun Jun 28 16:22:54 2015 +++ src/bin/cp/cp.1 Thu Aug 11 00:17:23 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.44 2015/06/28 16:22:54 wiz Exp $ +.\" $NetBSD: cp.1,v 1.45 2016/08/11 00:17:23 sevan Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd March 25, 2012 +.Dd August 11, 2016 .Dt CP 1 .Os .Sh NAME @@ -255,3 +255,8 @@ The .Fl v option is an extension to .St -p1003.2 . +.Sh HISTORY +A +.Nm +utility appeared in +.At v1 .
CVS commit: src/bin/cp
Module Name:src Committed By: mrg Date: Mon Feb 29 04:22:21 UTC 2016 Modified Files: src/bin/cp: utils.c Log Message: for display in the (post) SIGINFO handler use off_t not size_t for file sizes. fixes incorrect reporting errors on 32 bit platforms with >4GB file sizes. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.44 src/bin/cp/utils.c:1.45 --- src/bin/cp/utils.c:1.44 Tue Mar 3 00:20:38 2015 +++ src/bin/cp/utils.c Mon Feb 29 04:22:21 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.44 2015/03/03 00:20:38 enami Exp $ */ +/* $NetBSD: utils.c,v 1.45 2016/02/29 04:22:21 mrg Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.44 2015/03/03 00:20:38 enami Exp $"); +__RCSID("$NetBSD: utils.c,v 1.45 2016/02/29 04:22:21 mrg Exp $"); #endif #endif /* not lint */ @@ -77,17 +77,18 @@ set_utimes(const char *file, struct stat struct finfo { const char *from; const char *to; - size_t size; + off_t size; }; static void -progress(const struct finfo *fi, size_t written) +progress(const struct finfo *fi, off_t written) { int pcent = (int)((100.0 * written) / fi->size); pinfo = 0; - (void)fprintf(stderr, "%s => %s %zu/%zu bytes %d%% written\n", - fi->from, fi->to, written, fi->size, pcent); + (void)fprintf(stderr, "%s => %s %llu/%llu bytes %d%% written\n", + fi->from, fi->to, (unsigned long long)written, + (unsigned long long)fi->size, pcent); } int @@ -97,7 +98,7 @@ copy_file(FTSENT *entp, int dne) struct stat to_stat, *fs; int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount; char *p; - size_t ptotal = 0; + off_t ptotal = 0; if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) { warn("%s", entp->fts_path); @@ -184,7 +185,7 @@ copy_file(FTSENT *entp, int dne) fi.from = entp->fts_path; fi.to = to.p_path; - fi.size = (size_t)fs->st_size; + fi.size = fs->st_size; /* * Mmap and write if less than 8M (the limit is so
CVS commit: src/bin/cp
Module Name:src Committed By: uwe Date: Sat Mar 5 19:48:56 UTC 2016 Modified Files: src/bin/cp: cp.c Log Message: The '-i' flag should work regardless of whether the standard input is a terminal. The Open Group notes this historic behavior and correctly notes that it doesn't make much sense. Note also, that mv(1) has always respected its '-i' regardless of whether the standard input is a terminal. >From Timo Buhrmester. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.58 src/bin/cp/cp.c:1.59 --- src/bin/cp/cp.c:1.58 Wed Jan 4 15:58:37 2012 +++ src/bin/cp/cp.c Sat Mar 5 19:48:55 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $ */ +/* $NetBSD: cp.c,v 1.59 2016/03/05 19:48:55 uwe Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $"); +__RCSID("$NetBSD: cp.c,v 1.59 2016/03/05 19:48:55 uwe Exp $"); #endif #endif /* not lint */ @@ -145,7 +145,7 @@ main(int argc, char *argv[]) iflag = 0; break; case 'i': - iflag = isatty(fileno(stdin)); + iflag = 1; fflag = 0; break; case 'l':
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Sun Mar 25 22:37:08 UTC 2012 Modified Files: src/bin/cp: cp.1 Log Message: >From patch by Bug Hunting: - bump the manpage's date (because of the next change); - note that cp(1) does not preserve hard links (even with `-R'), and refer to pax(1) there as well as in the `SEE ALSO' section for such functionality (this change is based upon a similar note in FreeBSD's version of the manpage); - change a wording, for more overall consistency. To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.41 src/bin/cp/cp.1:1.42 --- src/bin/cp/cp.1:1.41 Wed Aug 3 15:44:15 2011 +++ src/bin/cp/cp.1 Sun Mar 25 22:37:08 2012 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.41 2011/08/03 15:44:15 dholland Exp $ +.\" $NetBSD: cp.1,v 1.42 2012/03/25 22:37:08 wiz Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd August 3, 2011 +.Dd March 25, 2012 .Dt CP 1 .Os .Sh NAME @@ -151,8 +151,15 @@ followed, and for to create special files rather than copying them as normal files. Created directories have the same mode as the corresponding source directory, unmodified by the process's umask. +.Pp +Note that +.Nm +copies hard linked files as separate files. +If you need to preserve hard links, consider using a utility like +.Xr pax 1 +instead. .It Fl v -Cause +Causes .Nm to be verbose, showing files as they are copied. .El @@ -219,6 +226,7 @@ discouraged, as it does not correctly co or fifo's. .Sh SEE ALSO .Xr mv 1 , +.Xr pax 1 , .Xr rcp 1 , .Xr umask 2 , .Xr fts 3 ,
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Wed Jan 4 15:58:37 UTC 2012 Modified Files: src/bin/cp: cp.c extern.h utils.c Log Message: Add siginfo support from Daniel Loffgren. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/bin/cp/cp.c cvs rdiff -u -r1.16 -r1.17 src/bin/cp/extern.h cvs rdiff -u -r1.40 -r1.41 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.57 src/bin/cp/cp.c:1.58 --- src/bin/cp/cp.c:1.57 Thu Aug 18 04:11:58 2011 +++ src/bin/cp/cp.c Wed Jan 4 10:58:37 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.57 2011/08/18 08:11:58 manu Exp $ */ +/* $NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: cp.c,v 1.57 2011/08/18 08:11:58 manu Exp $"); +__RCSID("$NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $"); #endif #endif /* not lint */ @@ -70,6 +70,7 @@ __RCSID("$NetBSD: cp.c,v 1.57 2011/08/18 #include #include #include +#include #include #include #include @@ -88,11 +89,18 @@ PATH_T to = { .p_end = to.p_path, .targe uid_t myuid; int Hflag, Lflag, Rflag, Pflag, fflag, iflag, lflag, pflag, rflag, vflag, Nflag; mode_t myumask; +sig_atomic_t pinfo; enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE }; -int main(int, char *[]); -int copy(char *[], enum op, int); +static int copy(char *[], enum op, int); + +static void +progress(int sig __unused) +{ + + pinfo++; +} int main(int argc, char *argv[]) @@ -210,6 +218,8 @@ main(int argc, char *argv[]) /* Set end of argument list for fts(3). */ argv[argc] = NULL; + (void)signal(SIGINFO, progress); + /* * Cp has two distinct cases: * @@ -310,7 +320,7 @@ popdne(void) return rv; } -int +static int copy(char *argv[], enum op type, int fts_options) { struct stat to_stat; Index: src/bin/cp/extern.h diff -u src/bin/cp/extern.h:1.16 src/bin/cp/extern.h:1.17 --- src/bin/cp/extern.h:1.16 Sun Feb 6 07:37:49 2011 +++ src/bin/cp/extern.h Wed Jan 4 10:58:37 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.16 2011/02/06 12:37:49 darcy Exp $ */ +/* $NetBSD: extern.h,v 1.17 2012/01/04 15:58:37 christos Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -44,6 +44,7 @@ extern PATH_T to; extern uid_t myuid; extern int Rflag, rflag, Hflag, Lflag, Pflag, fflag, iflag, lflag, pflag, Nflag; extern mode_t myumask; +extern sig_atomic_t pinfo; #include Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.40 src/bin/cp/utils.c:1.41 --- src/bin/cp/utils.c:1.40 Wed Aug 3 00:11:15 2011 +++ src/bin/cp/utils.c Wed Jan 4 10:58:37 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.40 2011/08/03 04:11:15 manu Exp $ */ +/* $NetBSD: utils.c,v 1.41 2012/01/04 15:58:37 christos Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.40 2011/08/03 04:11:15 manu Exp $"); +__RCSID("$NetBSD: utils.c,v 1.41 2012/01/04 15:58:37 christos Exp $"); #endif #endif /* not lint */ @@ -74,6 +74,22 @@ set_utimes(const char *file, struct stat return (0); } +struct finfo { + const char *from; + const char *to; + size_t size; +}; + +static void +progress(const struct finfo *fi, size_t written) +{ + int pcent = (int)((100.0 * written) / fi->size); + + pinfo = 0; + (void)fprintf(stderr, "%s => %s %zu/%zu bytes %d%% written\n", + fi->from, fi->to, written, fi->size, pcent); +} + int copy_file(FTSENT *entp, int dne) { @@ -81,6 +97,7 @@ copy_file(FTSENT *entp, int dne) struct stat to_stat, *fs; int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount; char *p; + size_t ptotal = 0; if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) { warn("%s", entp->fts_path); @@ -164,6 +181,12 @@ copy_file(FTSENT *entp, int dne) * now if it's empty, so let's not bother. */ if (fs->st_size > 0) { + struct finfo fi; + + fi.from = entp->fts_path; + fi.to = to.p_path; + fi.size = (size_t)fs->st_size; + /* * Mmap and write if less than 8M (the limit is so * we don't totally trash memory on big files). @@ -203,6 +226,9 @@ copy_file(FTSENT *entp, int dne) break; } remainder -= chunk; + ptotal += chunk; + if (pinfo) + progress(&fi, ptotal); } while (remainder > 0); if (munmap(p, fsize) < 0) { @@ -220,6 +246,9 @@ copy_file(FTSENT *entp, int dne) rval = 1; break; } +ptotal += wcount; +if (pinfo) + progress(&fi, ptotal); } if (rcount < 0) { warn("%s", entp->fts_path);
CVS commit: src/bin/cp
Module Name:src Committed By: dholland Date: Wed Dec 11 06:00:11 UTC 2013 Modified Files: src/bin/cp: utils.c Log Message: Remove entirely bogus /* NOTREACHED */ annotation. To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.41 src/bin/cp/utils.c:1.42 --- src/bin/cp/utils.c:1.41 Wed Jan 4 15:58:37 2012 +++ src/bin/cp/utils.c Wed Dec 11 06:00:11 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.41 2012/01/04 15:58:37 christos Exp $ */ +/* $NetBSD: utils.c,v 1.42 2013/12/11 06:00:11 dholland Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.41 2012/01/04 15:58:37 christos Exp $"); +__RCSID("$NetBSD: utils.c,v 1.42 2013/12/11 06:00:11 dholland Exp $"); #endif #endif /* not lint */ @@ -174,7 +174,6 @@ copy_file(FTSENT *entp, int dne) } return (0); } - /* NOTREACHED */ /* * There's no reason to do anything other than close the file
CVS commit: src/bin/cp
Module Name:src Committed By: pooka Date: Tue Sep 29 13:30:17 UTC 2009 Modified Files: src/bin/cp: cp.c Log Message: Remove fts sorting. It was originally put there to copy files before directories since files (usually) are in the same cylinder group and subdirectories aren't. However, this mostly changed with the new ffs dirpref algorithm in 2001. No sorting has two effects: 1) copy appears to be somewhat faster (e.g. on my laptop cp'ing build objdir to tmpfs is 7% faster after the change) 2) source file parameters no longer get randomly shuffled due to fts doing an unstable sort of them. this means that "cp 1 2 3 4 dest/" will copy the files in that order instead of e.g. 3 4 1 2. To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.51 src/bin/cp/cp.c:1.52 --- src/bin/cp/cp.c:1.51 Sun Jul 20 00:52:39 2008 +++ src/bin/cp/cp.c Tue Sep 29 13:30:17 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.51 2008/07/20 00:52:39 lukem Exp $ */ +/* $NetBSD: cp.c,v 1.52 2009/09/29 13:30:17 pooka Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: cp.c,v 1.51 2008/07/20 00:52:39 lukem Exp $"); +__RCSID("$NetBSD: cp.c,v 1.52 2009/09/29 13:30:17 pooka Exp $"); #endif #endif /* not lint */ @@ -92,7 +92,6 @@ int main(int, char *[]); int copy(char *[], enum op, int); -int mastercmp(const FTSENT **, const FTSENT **); int main(int argc, char *argv[]) @@ -295,7 +294,7 @@ dne = 0; base = 0; /* XXX gcc -Wuninitialized (see comment below) */ - if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL) + if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL) err(EXIT_FAILURE, "%s", argv[0]); /* NOTREACHED */ for (any_failed = 0; (curr = fts_read(ftsp)) != NULL;) { @@ -515,29 +514,3 @@ (void)fts_close(ftsp); return (any_failed); } - -/* - * 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(const FTSENT **a, const FTSENT **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); -}
CVS commit: src/bin/cp
Module Name:src Committed By: pooka Date: Thu Oct 8 20:36:41 UTC 2009 Modified Files: src/bin/cp: cp.c Log Message: Fix the "dne" handling and chmod behaviour properly: values of dne need to be on a stack instead of being a single variable since directories are processed depth-first. Otherwise dne randomly depends on the previously processed entry. This fixes both chmod of non-created directories (they used to be chmod'd even when not created if their last child element did not exist in the target subtree) and a "foo exists" bug exposed by my last commit which removed directory sorting. all regression tests passed To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.52 src/bin/cp/cp.c:1.53 --- src/bin/cp/cp.c:1.52 Tue Sep 29 13:30:17 2009 +++ src/bin/cp/cp.c Thu Oct 8 20:36:41 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.52 2009/09/29 13:30:17 pooka Exp $ */ +/* $NetBSD: cp.c,v 1.53 2009/10/08 20:36:41 pooka Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: cp.c,v 1.52 2009/09/29 13:30:17 pooka Exp $"); +__RCSID("$NetBSD: cp.c,v 1.53 2009/10/08 20:36:41 pooka Exp $"); #endif #endif /* not lint */ @@ -65,6 +65,7 @@ #include #include +#include #include #include #include @@ -280,6 +281,26 @@ /* NOTREACHED */ } +static int dnestack[MAXPATHLEN]; /* unlikely we'll have more nested dirs */ +static ssize_t dnesp; +static void +pushdne(int dne) +{ + + dnestack[dnesp++] = dne; + assert(dnesp < MAXPATHLEN); +} + +static int +popdne(void) +{ + int rv; + + rv = dnestack[--dnesp]; + assert(dnesp >= 0); + return rv; +} + int copy(char *argv[], enum op type, int fts_options) { @@ -291,7 +312,6 @@ size_t nlen; char *p, *target_mid; - dne = 0; base = 0; /* XXX gcc -Wuninitialized (see comment below) */ if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL) @@ -398,8 +418,7 @@ this_failed = any_failed = 1; continue; } - if (!S_ISDIR(curr->fts_statp->st_mode)) -dne = 0; + dne = 0; } switch (curr->fts_statp->st_mode & S_IFMT) { @@ -439,6 +458,7 @@ * 555) and not causing a permissions race. If the * umask blocks owner writes, we fail.. */ +pushdne(dne); if (dne) { if (mkdir(to.p_path, curr->fts_statp->st_mode | S_IRWXU) < 0) @@ -462,16 +482,9 @@ */ if (pflag && setfile(curr->fts_statp, 0)) this_failed = any_failed = 1; -else if (dne) +else if ((dne = popdne())) (void)chmod(to.p_path, curr->fts_statp->st_mode); - -/* - * Since this is the second pass, we already - * noted (and acted on) the existence of the - * directory. - */ -dne = 0; } else {
CVS commit: src/bin/cp
Module Name:src Committed By: yamt Date: Mon Jan 24 02:44:22 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: document what -a is for To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.33 src/bin/cp/cp.1:1.34 --- src/bin/cp/cp.1:1.33 Wed Dec 22 09:02:32 2010 +++ src/bin/cp/cp.1 Mon Jan 24 02:44:22 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.33 2010/12/22 09:02:32 wiz Exp $ +.\" $NetBSD: cp.1,v 1.34 2011/01/24 02:44:22 yamt Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -220,9 +220,13 @@ utility is expected to be .St -p1003.2 compatible. +.Pp The .Fl a is a non-standard extension. +It is intended to be compatible with the same option which +other implementations, namely GNU coreutils and FreeBSD, +of this utility have. .Pp The .Fl v
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Mon Jan 24 07:22:57 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: Use Fx. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.34 src/bin/cp/cp.1:1.35 --- src/bin/cp/cp.1:1.34 Mon Jan 24 02:44:22 2011 +++ src/bin/cp/cp.1 Mon Jan 24 07:22:57 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.34 2011/01/24 02:44:22 yamt Exp $ +.\" $NetBSD: cp.1,v 1.35 2011/01/24 07:22:57 wiz Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -225,7 +225,8 @@ .Fl a is a non-standard extension. It is intended to be compatible with the same option which -other implementations, namely GNU coreutils and FreeBSD, +other implementations, namely GNU coreutils and +.Fx , of this utility have. .Pp The
CVS commit: src/bin/cp
Module Name:src Committed By: darcy Date: Sun Feb 6 12:37:49 UTC 2011 Modified Files: src/bin/cp: cp.1 cp.c extern.h utils.c Log Message: Add -l option to copy a tree as links. Non-standard option similar to Gnutools cp(1) Approved by core. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/bin/cp/cp.1 cvs rdiff -u -r1.54 -r1.55 src/bin/cp/cp.c cvs rdiff -u -r1.15 -r1.16 src/bin/cp/extern.h cvs rdiff -u -r1.38 -r1.39 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.35 src/bin/cp/cp.1:1.36 --- src/bin/cp/cp.1:1.35 Mon Jan 24 07:22:57 2011 +++ src/bin/cp/cp.1 Sun Feb 6 12:37:48 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.35 2011/01/24 07:22:57 wiz Exp $ +.\" $NetBSD: cp.1,v 1.36 2011/02/06 12:37:48 darcy Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd December 21, 2010 +.Dd February 6, 2010 .Dt CP 1 .Os .Sh NAME @@ -45,7 +45,7 @@ .Op Fl H | Fl L | Fl P .Oc .Op Fl f | i -.Op Fl aNpv +.Op Fl alNpv .Ar source_file target_file .Nm cp .Oo @@ -53,7 +53,7 @@ .Op Fl H | Fl L | Fl P .Oc .Op Fl f | i -.Op Fl aNpv +.Op Fl alNpv .Ar source_file ... target_directory .Sh DESCRIPTION In the first synopsis form, the @@ -104,6 +104,9 @@ If the .Fl R option is specified, all symbolic links are followed. +.It Fl l +Create hard links to regular files in a hierarchy instead of copying. +The -l option is expected to behave similar to cp(1) in GNU coreutils. .It Fl N When used with .Fl p , Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.54 src/bin/cp/cp.c:1.55 --- src/bin/cp/cp.c:1.54 Tue Dec 21 20:56:01 2010 +++ src/bin/cp/cp.c Sun Feb 6 12:37:49 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.54 2010/12/21 20:56:01 christos Exp $ */ +/* $NetBSD: cp.c,v 1.55 2011/02/06 12:37:49 darcy Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: cp.c,v 1.54 2010/12/21 20:56:01 christos Exp $"); +__RCSID("$NetBSD: cp.c,v 1.55 2011/02/06 12:37:49 darcy Exp $"); #endif #endif /* not lint */ @@ -86,7 +86,7 @@ PATH_T to = { .p_end = to.p_path, .target_end = empty }; uid_t myuid; -int Hflag, Lflag, Rflag, Pflag, fflag, iflag, pflag, rflag, vflag, Nflag; +int Hflag, Lflag, Rflag, Pflag, fflag, iflag, lflag, pflag, rflag, vflag, Nflag; mode_t myumask; enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE }; @@ -106,7 +106,7 @@ (void)setlocale(LC_ALL, ""); Hflag = Lflag = Pflag = Rflag = 0; - while ((ch = getopt(argc, argv, "HLNPRfaiprv")) != -1) + while ((ch = getopt(argc, argv, "HLNPRfailprv")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -140,6 +140,9 @@ iflag = isatty(fileno(stdin)); fflag = 0; break; + case 'l': + lflag = 1; + break; case 'p': pflag = 1; break; Index: src/bin/cp/extern.h diff -u src/bin/cp/extern.h:1.15 src/bin/cp/extern.h:1.16 --- src/bin/cp/extern.h:1.15 Sun Jul 16 16:22:24 2006 +++ src/bin/cp/extern.h Sun Feb 6 12:37:49 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.15 2006/07/16 16:22:24 jschauma Exp $ */ +/* $NetBSD: extern.h,v 1.16 2011/02/06 12:37:49 darcy Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -42,7 +42,7 @@ extern PATH_T to; extern uid_t myuid; -extern int Rflag, rflag, Hflag, Lflag, Pflag, fflag, iflag, pflag, Nflag; +extern int Rflag, rflag, Hflag, Lflag, Pflag, fflag, iflag, lflag, pflag, Nflag; extern mode_t myumask; #include Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.38 src/bin/cp/utils.c:1.39 --- src/bin/cp/utils.c:1.38 Tue Jan 4 10:35:10 2011 +++ src/bin/cp/utils.c Sun Feb 6 12:37:49 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.38 2011/01/04 10:35:10 wiz Exp $ */ +/* $NetBSD: utils.c,v 1.39 2011/02/06 12:37:49 darcy Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.38 2011/01/04 10:35:10 wiz Exp $"); +__RCSID("$NetBSD: utils.c,v 1.39 2011/02/06 12:37:49 darcy Exp $"); #endif #endif /* not lint */ @@ -145,11 +145,23 @@ rval = 0; + /* if hard linking then simply close the open fds, link and return */ + if (lflag) { + (void)close(from_fd); + (void)close(to_fd); + (void)unlink(to.p_path); + if (link(entp->fts_path, to.p_path)) { + warn("%s", to.p_path); + return (1); + } + return (0); + } + /* NOTREACHED */ + /* * There's no reason to do anything other than close the file * now if it's empty, so let's not bother. */ - if (fs->st_size > 0) { /* * Mmap and write if less than 8M (the limit is so @@ -215,8 +227,9 @@ } } + (void)close(from_fd); + if (rval == 1) { - (void)close(from_fd); (void)c
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Sun Feb 6 12:49:33 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: Put -l compatibility note in STANDARDS section. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.36 src/bin/cp/cp.1:1.37 --- src/bin/cp/cp.1:1.36 Sun Feb 6 12:37:48 2011 +++ src/bin/cp/cp.1 Sun Feb 6 12:49:32 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.36 2011/02/06 12:37:48 darcy Exp $ +.\" $NetBSD: cp.1,v 1.37 2011/02/06 12:49:32 wiz Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -106,7 +106,6 @@ option is specified, all symbolic links are followed. .It Fl l Create hard links to regular files in a hierarchy instead of copying. -The -l option is expected to behave similar to cp(1) in GNU coreutils. .It Fl N When used with .Fl p , @@ -226,8 +225,10 @@ .Pp The .Fl a -is a non-standard extension. -It is intended to be compatible with the same option which +and +.Fl l +flags are non-standard extensions. +They are intended to be compatible with the same options which other implementations, namely GNU coreutils and .Fx , of this utility have.
CVS commit: src/bin/cp
Module Name:src Committed By: pooka Date: Fri Oct 22 17:56:06 UTC 2010 Modified Files: src/bin/cp: utils.c Log Message: Disable mmap path. With the current vnode locking scheme it has a very annoying property: if the source media is slow (like a slow network), the target file will be locked for the duration of the entire max 8MB write and cause processes attempting to e.g. stat() it to "tstile" (for several minutes in the worst case). Revisit this if/when vnode locking gets a little smarter. chs ok (although he would rather see vnode locking improvements, but that's a slightly larger project) To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.34 src/bin/cp/utils.c:1.35 --- src/bin/cp/utils.c:1.34 Fri Oct 26 16:21:25 2007 +++ src/bin/cp/utils.c Fri Oct 22 17:56:06 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.34 2007/10/26 16:21:25 hira Exp $ */ +/* $NetBSD: utils.c,v 1.35 2010/10/22 17:56:06 pooka Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.34 2007/10/26 16:21:25 hira Exp $"); +__RCSID("$NetBSD: utils.c,v 1.35 2010/10/22 17:56:06 pooka Exp $"); #endif #endif /* not lint */ @@ -75,7 +75,6 @@ static char buf[MAXBSIZE]; struct stat to_stat, *fs; int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount; - char *p; if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) { warn("%s", entp->fts_path); @@ -147,6 +146,16 @@ if (fs->st_size > 0) { + /* + * Disable use of mmap. With the current vnode locking + * scheme it has a very annoying property: if the source + * media is slow (like a slow network), the target file + * will be locked for the duration of the entire max 8MB + * write and cause processes attempting to e.g. stat() it + * to "tstile". Revisit when vnode locking gets a little + * smarter. + */ +#ifdef VNODE_LOCKING_IS_SMARTER_NOW /* * Mmap and write if less than 8M (the limit is so * we don't totally trash memory on big files). @@ -155,6 +164,8 @@ if (fs->st_size <= 8 * 1048576) { size_t fsize = (size_t)fs->st_size; + char *p; + p = mmap(NULL, fsize, PROT_READ, MAP_FILE|MAP_SHARED, from_fd, (off_t)0); if (p == MAP_FAILED) { @@ -174,6 +185,7 @@ } } else { mmap_failed: +#endif while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) { wcount = write(to_fd, buf, (size_t)rcount); if (rcount != wcount || wcount == -1) { @@ -186,7 +198,9 @@ warn("%s", entp->fts_path); rval = 1; } +#ifdef VNODE_LOCKING_IS_SMARTER_NOW } +#endif } if (rval == 1) {
CVS commit: src/bin/cp
Module Name:src Committed By: tron Date: Mon Oct 25 08:19:47 UTC 2010 Modified Files: src/bin/cp: utils.c Log Message: Re-enable support for reading files smaller of at most 8MB via mmap(2). Write out the mmap-ed data in small chunks to avoid locking the output file for a long time. Suggested by David Holland on "source-changes-d" mailing list. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.35 src/bin/cp/utils.c:1.36 --- src/bin/cp/utils.c:1.35 Fri Oct 22 17:56:06 2010 +++ src/bin/cp/utils.c Mon Oct 25 08:19:47 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.35 2010/10/22 17:56:06 pooka Exp $ */ +/* $NetBSD: utils.c,v 1.36 2010/10/25 08:19:47 tron Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.35 2010/10/22 17:56:06 pooka Exp $"); +__RCSID("$NetBSD: utils.c,v 1.36 2010/10/25 08:19:47 tron Exp $"); #endif #endif /* not lint */ @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,9 @@ #include "extern.h" +#define MMAP_MAX_SIZE (8 * 1048576) +#define MMAP_MAX_WRITE (64 * 1024) + int set_utimes(const char *file, struct stat *fs) { @@ -75,6 +79,7 @@ static char buf[MAXBSIZE]; struct stat to_stat, *fs; int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount; + char *p; if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) { warn("%s", entp->fts_path); @@ -145,47 +150,55 @@ */ if (fs->st_size > 0) { - - /* - * Disable use of mmap. With the current vnode locking - * scheme it has a very annoying property: if the source - * media is slow (like a slow network), the target file - * will be locked for the duration of the entire max 8MB - * write and cause processes attempting to e.g. stat() it - * to "tstile". Revisit when vnode locking gets a little - * smarter. - */ -#ifdef VNODE_LOCKING_IS_SMARTER_NOW /* * Mmap and write if less than 8M (the limit is so * we don't totally trash memory on big files). * This is really a minor hack, but it wins some CPU back. */ + bool use_read; - if (fs->st_size <= 8 * 1048576) { + use_read = true; + if (fs->st_size <= MMAP_MAX_SIZE) { size_t fsize = (size_t)fs->st_size; - char *p; - p = mmap(NULL, fsize, PROT_READ, MAP_FILE|MAP_SHARED, from_fd, (off_t)0); - if (p == MAP_FAILED) { -goto mmap_failed; - } else { + if (p != MAP_FAILED) { +size_t remainder; + +use_read = false; + (void) madvise(p, (size_t)fs->st_size, MADV_SEQUENTIAL); -if (write(to_fd, p, fsize) != -fs->st_size) { - warn("%s", to.p_path); - rval = 1; -} + +/* + * Write out the data in small chunks to + * avoid locking the output file for a + * long time if the reading the data from + * the source is slow. + */ +remainder = fsize; +do { + ssize_t chunk; + + chunk = (remainder > MMAP_MAX_WRITE) ? + MMAP_MAX_WRITE : remainder; + if (write(to_fd, &p[fsize - remainder], + chunk) != chunk) { + warn("%s", to.p_path); + rval = 1; + break; + } + remainder -= chunk; +} while (remainder > 0); + if (munmap(p, fsize) < 0) { warn("%s", entp->fts_path); rval = 1; } } - } else { -mmap_failed: -#endif + } + + if (use_read) { while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) { wcount = write(to_fd, buf, (size_t)rcount); if (rcount != wcount || wcount == -1) { @@ -198,9 +211,7 @@ warn("%s", entp->fts_path); rval = 1; } -#ifdef VNODE_LOCKING_IS_SMARTER_NOW } -#endif } if (rval == 1) {
CVS commit: src/bin/cp
Module Name:src Committed By: manu Date: Wed Aug 3 12:55:03 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: iExplain what happens to extended attriutes when -p is used. To generate a diff of this commit: cvs rdiff -u -r1.38 -r1.39 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.38 src/bin/cp/cp.1:1.39 --- src/bin/cp/cp.1:1.38 Sat Apr 2 08:38:56 2011 +++ src/bin/cp/cp.1 Wed Aug 3 12:55:03 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.38 2011/04/02 08:38:56 mbalmer Exp $ +.\" $NetBSD: cp.1,v 1.39 2011/08/03 12:55:03 manu Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -117,7 +117,8 @@ Causes .Nm to preserve in the copy as many of the modification time, access time, -file flags, file mode, user ID, and group ID as allowed by permissions. +file flags, file mode, user ID, group ID, and extended attributes, +as allowed by permissions. .Pp If the user ID and group ID cannot be preserved, no error message is displayed and the exit value is not altered. @@ -132,6 +133,13 @@ and either the user ID or group ID cannot be preserved, neither the set user ID or set group ID bits are preserved in the copy's permissions. +.Pp +Extended attributes from all accessible namespaces are copied, the +others being ignored. If an error occur during the copy, a message is +displayed and +.Nm cp +skips +the other extended attributes for the file. .It Fl R If .Ar source_file
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Wed Aug 3 14:02:59 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: New sentence, new line. Remove trailing whitespace. Bump date for previous. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.39 src/bin/cp/cp.1:1.40 --- src/bin/cp/cp.1:1.39 Wed Aug 3 12:55:03 2011 +++ src/bin/cp/cp.1 Wed Aug 3 14:02:59 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.39 2011/08/03 12:55:03 manu Exp $ +.\" $NetBSD: cp.1,v 1.40 2011/08/03 14:02:59 wiz Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd April 2, 2011 +.Dd August 3, 2011 .Dt CP 1 .Os .Sh NAME @@ -135,11 +135,10 @@ permissions. .Pp Extended attributes from all accessible namespaces are copied, the -others being ignored. If an error occur during the copy, a message is -displayed and +others being ignored. +If an error occur during the copy, a message is displayed and .Nm cp -skips -the other extended attributes for the file. +skips the other extended attributes for the file. .It Fl R If .Ar source_file
CVS commit: src/bin/cp
Module Name:src Committed By: dholland Date: Wed Aug 3 15:44:15 UTC 2011 Modified Files: src/bin/cp: cp.1 Log Message: Adjust wording of previous and fix a couple grammar slipups/typos. To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.40 src/bin/cp/cp.1:1.41 --- src/bin/cp/cp.1:1.40 Wed Aug 3 14:02:59 2011 +++ src/bin/cp/cp.1 Wed Aug 3 15:44:15 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.40 2011/08/03 14:02:59 wiz Exp $ +.\" $NetBSD: cp.1,v 1.41 2011/08/03 15:44:15 dholland Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -134,11 +134,11 @@ the set user ID or set group ID bits are preserved in the copy's permissions. .Pp -Extended attributes from all accessible namespaces are copied, the -others being ignored. -If an error occur during the copy, a message is displayed and -.Nm cp -skips the other extended attributes for the file. +Extended attributes from all accessible namespaces are copied; +others are ignored. +If an error occurs during this copy, a message is displayed and +.Nm +skips the other extended attributes for that file. .It Fl R If .Ar source_file
CVS commit: src/bin/cp
Module Name:src Committed By: manu Date: Thu Aug 18 08:11:59 UTC 2011 Modified Files: src/bin/cp: cp.c Log Message: Remove warning about system extended attributes that cannot be copied, since it will always be displayed when an unprivilegied user moves files across filesystems (mv(1) uses cp -p in that case). After all, there is no warning that we loose a setuid bit during a move or copy, so this makes sense. Fixes bin/45259 To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/bin/cp/cp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.56 src/bin/cp/cp.c:1.57 --- src/bin/cp/cp.c:1.56 Wed Aug 3 04:11:15 2011 +++ src/bin/cp/cp.c Thu Aug 18 08:11:58 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.56 2011/08/03 04:11:15 manu Exp $ */ +/* $NetBSD: cp.c,v 1.57 2011/08/18 08:11:58 manu Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: cp.c,v 1.56 2011/08/03 04:11:15 manu Exp $"); +__RCSID("$NetBSD: cp.c,v 1.57 2011/08/18 08:11:58 manu Exp $"); #endif #endif /* not lint */ @@ -197,13 +197,6 @@ myumask = umask(0); (void)umask(myumask); - /* - * Warn that system extended attributes will not be preserved - * if not root - */ - if ((myuid != 0) && pflag) - warnx("system extended attribute will not be preserved"); - /* Save the target base in "to". */ target = argv[--argc]; if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path))
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Tue Dec 21 20:56:01 UTC 2010 Modified Files: src/bin/cp: cp.1 cp.c utils.c Log Message: Add -a archive flag. from Aleksey Cheusov To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/bin/cp/cp.1 cvs rdiff -u -r1.53 -r1.54 src/bin/cp/cp.c cvs rdiff -u -r1.36 -r1.37 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.30 src/bin/cp/cp.1:1.31 --- src/bin/cp/cp.1:1.30 Fri Oct 26 12:31:16 2007 +++ src/bin/cp/cp.1 Tue Dec 21 15:56:01 2010 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.30 2007/10/26 16:31:16 hira Exp $ +.\" $NetBSD: cp.1,v 1.31 2010/12/21 20:56:01 christos Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -45,7 +45,7 @@ .Op Fl H | Fl L | Fl P .Oc .Op Fl f | i -.Op Fl Npv +.Op Fl aNpv .Ar source_file target_file .Nm cp .Oo @@ -53,7 +53,7 @@ .Op Fl H | Fl L | Fl P .Oc .Op Fl f | i -.Op Fl Npv +.Op Fl aNpv .Ar source_file ... target_directory .Sh DESCRIPTION In the first synopsis form, the @@ -100,6 +100,10 @@ If the .Fl R option is specified, all symbolic links are followed. +.It Fl a +Archive mode. +Same as +.Fl RpP . .It Fl N When used with .Fl p , Index: src/bin/cp/cp.c diff -u src/bin/cp/cp.c:1.53 src/bin/cp/cp.c:1.54 --- src/bin/cp/cp.c:1.53 Thu Oct 8 16:36:41 2009 +++ src/bin/cp/cp.c Tue Dec 21 15:56:01 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: cp.c,v 1.53 2009/10/08 20:36:41 pooka Exp $ */ +/* $NetBSD: cp.c,v 1.54 2010/12/21 20:56:01 christos Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: cp.c,v 1.53 2009/10/08 20:36:41 pooka Exp $"); +__RCSID("$NetBSD: cp.c,v 1.54 2010/12/21 20:56:01 christos Exp $"); #endif #endif /* not lint */ @@ -106,7 +106,7 @@ (void)setlocale(LC_ALL, ""); Hflag = Lflag = Pflag = Rflag = 0; - while ((ch = getopt(argc, argv, "HLNPRfiprv")) != -1) + while ((ch = getopt(argc, argv, "HLNPRfaiprv")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -126,6 +126,12 @@ case 'R': Rflag = 1; break; + case 'a': + Pflag = 1; + pflag = 1; + Rflag = 1; + Hflag = Lflag = 0; + break; case 'f': fflag = 1; iflag = 0; Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.36 src/bin/cp/utils.c:1.37 --- src/bin/cp/utils.c:1.36 Mon Oct 25 04:19:47 2010 +++ src/bin/cp/utils.c Tue Dec 21 15:56:01 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.36 2010/10/25 08:19:47 tron Exp $ */ +/* $NetBSD: utils.c,v 1.37 2010/12/21 20:56:01 christos Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.36 2010/10/25 08:19:47 tron Exp $"); +__RCSID("$NetBSD: utils.c,v 1.37 2010/12/21 20:56:01 christos Exp $"); #endif #endif /* not lint */ @@ -367,8 +367,8 @@ usage(void) { (void)fprintf(stderr, - "usage: %s [-R [-H | -L | -P]] [-f | -i] [-Npv] src target\n" - " %s [-R [-H | -L | -P]] [-f | -i] [-Npv] src1 ... srcN directory\n", + "usage: %s [-R [-H | -L | -P]] [-f | -i] [-aNpv] src target\n" + " %s [-R [-H | -L | -P]] [-f | -i] [-aNpv] src1 ... srcN directory\n", getprogname(), getprogname()); exit(1); /* NOTREACHED */
CVS commit: src/bin/cp
Module Name:src Committed By: christos Date: Wed Dec 22 05:46:26 UTC 2010 Modified Files: src/bin/cp: cp.1 Log Message: Say that -a is non-standard and -P is the default. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.31 src/bin/cp/cp.1:1.32 --- src/bin/cp/cp.1:1.31 Tue Dec 21 15:56:01 2010 +++ src/bin/cp/cp.1 Wed Dec 22 00:46:25 2010 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.31 2010/12/21 20:56:01 christos Exp $ +.\" $NetBSD: cp.1,v 1.32 2010/12/22 05:46:25 christos Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -110,6 +110,7 @@ don't copy file flags. .It Fl P No symbolic links are followed. +This is the default. .It Fl p Causes .Nm @@ -219,6 +220,9 @@ utility is expected to be .St -p1003.2 compatible. +The +.Fl a +is a non-standard extension. .Pp The .Fl v
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Wed Dec 22 09:02:32 UTC 2010 Modified Files: src/bin/cp: cp.1 Log Message: Sort option descriptions, bump date for -a. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.32 src/bin/cp/cp.1:1.33 --- src/bin/cp/cp.1:1.32 Wed Dec 22 05:46:25 2010 +++ src/bin/cp/cp.1 Wed Dec 22 09:02:32 2010 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.32 2010/12/22 05:46:25 christos Exp $ +.\" $NetBSD: cp.1,v 1.33 2010/12/22 09:02:32 wiz Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd August 15, 2005 +.Dd December 21, 2010 .Dt CP 1 .Os .Sh NAME @@ -74,6 +74,10 @@ .Pp The following options are available: .Bl -tag -width flag +.It Fl a +Archive mode. +Same as +.Fl RpP . .It Fl f For each existing destination pathname, attempt to overwrite it. If permissions do not allow copy to succeed, remove it and create a new @@ -100,10 +104,6 @@ If the .Fl R option is specified, all symbolic links are followed. -.It Fl a -Archive mode. -Same as -.Fl RpP . .It Fl N When used with .Fl p ,
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Tue Jan 4 10:35:10 UTC 2011 Modified Files: src/bin/cp: utils.c Log Message: Fix fd leak in error case. Found by cppcheck. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.37 src/bin/cp/utils.c:1.38 --- src/bin/cp/utils.c:1.37 Tue Dec 21 20:56:01 2010 +++ src/bin/cp/utils.c Tue Jan 4 10:35:10 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.37 2010/12/21 20:56:01 christos Exp $ */ +/* $NetBSD: utils.c,v 1.38 2011/01/04 10:35:10 wiz Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.37 2010/12/21 20:56:01 christos Exp $"); +__RCSID("$NetBSD: utils.c,v 1.38 2011/01/04 10:35:10 wiz Exp $"); #endif #endif /* not lint */ @@ -117,6 +117,7 @@ lstat(to.p_path, &sb) : stat(to.p_path, &sb); if (sval == -1) { warn("stat: %s", to.p_path); + (void)close(from_fd); return (1); }
CVS commit: src/bin/cp
Module Name:src Committed By: enami Date: Tue Mar 3 00:20:38 UTC 2015 Modified Files: src/bin/cp: utils.c Log Message: Fix the name of failed function in warning message. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/bin/cp/utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/utils.c diff -u src/bin/cp/utils.c:1.43 src/bin/cp/utils.c:1.44 --- src/bin/cp/utils.c:1.43 Mon Mar 2 03:17:24 2015 +++ src/bin/cp/utils.c Tue Mar 3 00:20:38 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: utils.c,v 1.43 2015/03/02 03:17:24 enami Exp $ */ +/* $NetBSD: utils.c,v 1.44 2015/03/03 00:20:38 enami Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #else -__RCSID("$NetBSD: utils.c,v 1.43 2015/03/02 03:17:24 enami Exp $"); +__RCSID("$NetBSD: utils.c,v 1.44 2015/03/03 00:20:38 enami Exp $"); #endif #endif /* not lint */ @@ -68,7 +68,7 @@ set_utimes(const char *file, struct stat ts[1] = fs->st_mtimespec; if (lutimens(file, ts)) { - warn("lutimes: %s", file); + warn("lutimens: %s", file); return (1); } return (0);
CVS commit: src/bin/cp
Module Name:src Committed By: wiz Date: Sun Jun 28 16:22:54 UTC 2015 Modified Files: src/bin/cp: cp.1 Log Message: Add serial comma, use upper case for abbreviation, and remove apostrophe for plural. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/bin/cp/cp.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/bin/cp/cp.1 diff -u src/bin/cp/cp.1:1.43 src/bin/cp/cp.1:1.44 --- src/bin/cp/cp.1:1.43 Tue Dec 17 09:54:08 2013 +++ src/bin/cp/cp.1 Sun Jun 28 16:22:54 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: cp.1,v 1.43 2013/12/17 09:54:08 apb Exp $ +.\" $NetBSD: cp.1,v 1.44 2015/06/28 16:22:54 wiz Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -225,8 +225,8 @@ utility had a .Fl r option. This implementation supports that option, however, its use is strongly -discouraged, as it does not correctly copy special files, symbolic links -or fifo's. +discouraged, as it does not correctly copy special files, symbolic links, +or FIFOs. .Sh SEE ALSO .Xr mv 1 , .Xr pax 1 ,