Home | History | Annotate | only in /src/bin/cp
History log of /src/bin/cp
RevisionDateAuthorComments
 1.10 17-May-2020  christos No ACL support for install media (SMALLPROG)
 1.9 20-Jul-1997  christos branches: 1.9.112;
Remove WARNS=1 from all the subdirectory Makefiles, and add it to Makefile.inc
now that all /bin has been cleaned.
 1.8 20-Jul-1997  thorpej Build with WARNS.
 1.7 21-Mar-1995  cgd convert to new RCS id conventions.
 1.6 22-Sep-1994  mycroft Merge 4.4-Lite version.
 1.5 07-Aug-1993  mycroft New version from uunet. Uses mmap().
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.112.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.9.112.1 21-Apr-2020  martin Sync with HEAD
 1.46 23-Dec-2018  gutteridge Clarify a sentence about the error handling of cp(1)'s -p option.
Addresses PR bin/40336.
 1.45 11-Aug-2016  sevan branches: 1.45.12; 1.45.14;
Document the version cp first appeared.
Bump date.
 1.44 28-Jun-2015  wiz Add serial comma, use upper case for abbreviation, and remove apostrophe for plural.
 1.43 17-Dec-2013  apb In all man pages that say:

The -H, -L and -P options are ignored unless the -R option is
specified. In addition, these options override each other and the
command's actions are determined by the last one specified.

Add:

The default is as if the -P option had been specified.
 1.42 25-Mar-2012  wiz branches: 1.42.2;
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.
 1.41 03-Aug-2011  dholland branches: 1.41.2;
Adjust wording of previous and fix a couple grammar slipups/typos.
 1.40 03-Aug-2011  wiz New sentence, new line. Remove trailing whitespace. Bump date for previous.
 1.39 03-Aug-2011  manu iExplain what happens to extended attriutes when -p is used.
 1.38 02-Apr-2011  mbalmer Wording fixes from Ryo HAYASAKA, thanks.
 1.37 06-Feb-2011  wiz Put -l compatibility note in STANDARDS section.
 1.36 06-Feb-2011  darcy Add -l option to copy a tree as links.
Non-standard option similar to Gnutools cp(1)
Approved by core.
 1.35 24-Jan-2011  wiz Use Fx.
 1.34 24-Jan-2011  yamt document what -a is for
 1.33 22-Dec-2010  wiz branches: 1.33.2;
Sort option descriptions, bump date for -a.
 1.32 22-Dec-2010  christos Say that -a is non-standard and -P is the default.
 1.31 21-Dec-2010  christos Add -a archive flag. from Aleksey Cheusov
 1.30 26-Oct-2007  hira Sync SYNOPSIS with usage() (correct location of -P).
 1.29 16-Jul-2006  jschauma branches: 1.29.10;
return functionality backed out yesterday after fixing the bug I had
introduced before. A regression test will be added to src/regress
shortly.
 1.28 15-Jul-2006  jschauma The last commit introduced a bug. Revert until that's found and fixed.
 1.27 15-Jul-2006  jschauma As suggested on tech-userlevel:
"-R" claims:
-R [...] Created directories have the same mode as the corre-
sponding source directory, unmodified
by the process' umask.

Make this actually true.

In addition, make '-P' (no symbolic links are followed) apply even if
'-R' is not specified. This allows users to overwrite symbolic links
with files and/or to copy symbolic links over a file without indirecting
through the link (ie a copy of a link turns the target into a link, not
a copy of the file pointed to by the source).
 1.26 10-Sep-2005  wiz Sort options. Simplify macro usage. Use standard EXIT STATUS section.
 1.25 15-Aug-2005  elad Add and document -N: When used with -p, it will not copy the file flags.
PR 13645.
 1.24 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.23 21-Dec-2002  wiz For each, not Foreach; from Adrian Mrva. Begin new sentence on new line.
 1.22 18-Dec-2002  wiz Drop trailing whitespace.
 1.21 18-Dec-2002  kleink Add -v to SYNOPSIS, clean up STANDARDS a little. Also, bump date for -v.
 1.20 16-Dec-2002  jrf Added a -v verbose option to the cp(1) command. Updated man page and utils as well. This applies to PR bin/16834. This change was approved by Christos.
 1.19 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.18 20-Dec-2001  wiz Drop unnecessary .Pps.
 1.17 20-Dec-2001  wiz Whitespace nits.
 1.16 04-Sep-2000  kleink For commands and utilities, use EXIT STATUS rather than RETURN VALUES as
appropriate (and documented in mdoc(7)).
 1.15 28-Aug-2000  hubertf Add 'RETURN VALUE' section header.
 1.14 22-Mar-1999  garbled branches: 1.14.10;
More and more .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Many more to
come.
 1.13 08-Oct-1998  wsanchez Fix bug where "cp -f" didn't work.
It's suppsed to remove the file and then copy, which it wasn't doing.
But no wait, it turns out that the described behaviour in the manual doesn't
agree with POSIX. So we change the above fix and the manual to "try copy, and
if fail, try remove, then copy".
Fix bug where "cp -R" didn't work on read-only directories:
It would make the directory, set the mode, and not be able to write files into it.
Don't bother mmap()ing files of zero length. Was a workaround for a bug in Rhapsody
mmap(), which didn't get along with such files, but makes sense anyway.
Fix race condition where "cp -p" would set the mod time of a file before close()ing
the file, which would update the mod time and therefore screw up the "-p" idea,
except, of course, while running in gdb, which sucked.
Add -f option to usage message in binary and man page. Already documented in man page.
 1.12 11-Oct-1997  enami Use .Nm "" instead of .Nm cp in SYNOPSIS.
 1.11 10-Oct-1997  lukem all but the first .Nm in SYNOPSIS need to be spelt out. [bin/4256]
 1.10 14-Sep-1997  lukem * getopt returns -1 not EOF
* cleanup use of .Nm in manpage
 1.9 25-Jul-1995  jtc Use "utility" instead of "command". Modern definitions of these terms
are distinct (See POSIX.2 glossary).

A utility is a executable, script or shell builtin; while a command
can be any of those things plus lists, pipelines, compound commands
(if, for, while) and shell function definitions.
 1.8 25-Jul-1995  jtc s/HISTORY/STANDARDS/; noted by Masanobu Saitoh in PR#1269
 1.7 21-Mar-1995  cgd convert to new RCS id conventions.
 1.6 22-Sep-1994  mycroft Merge 4.4-Lite version.
 1.5 07-Aug-1993  mycroft New version from uunet. Uses mmap().
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14.10.1 28-Aug-2000  hubertf Pull up to netbsd-1-5 branch, OK'd by thorpej:

Log Message:
> Add 'RETURN VALUE' section header.

Files & Revisionis:
> cvs rdiff -r1.19 -r1.20 basesrc/bin/cat/cat.1
> cvs rdiff -r1.12 -r1.13 basesrc/bin/chmod/chmod.1
> cvs rdiff -r1.14 -r1.15 basesrc/bin/cp/cp.1
> cvs rdiff -r1.8 -r1.9 basesrc/bin/dd/dd.1
> cvs rdiff -r1.9 -r1.10 basesrc/bin/echo/echo.1
> cvs rdiff -r1.11 -r1.12 basesrc/bin/expr/expr.1
> cvs rdiff -r1.25 -r1.26 basesrc/bin/ls/ls.1
> cvs rdiff -r1.10 -r1.11 basesrc/bin/mkdir/mkdir.1
> cvs rdiff -r1.23 -r1.24 basesrc/bin/mt/mt.1
> cvs rdiff -r1.12 -r1.13 basesrc/bin/mv/mv.1
> cvs rdiff -r1.16 -r1.17 basesrc/bin/pwd/pwd.1
> cvs rdiff -r1.9 -r1.10 basesrc/bin/rm/rm.1
> cvs rdiff -r1.11 -r1.12 basesrc/bin/rmdir/rmdir.1
> cvs rdiff -r1.35 -r1.36 basesrc/bin/sh/sh.1
> cvs rdiff -r1.11 -r1.12 basesrc/bin/sleep/sleep.1
> cvs rdiff -r1.20 -r1.21 basesrc/bin/stty/stty.1
 1.29.10.1 06-Nov-2007  matt sync with HEAD
 1.33.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.41.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.41.2.1 17-Apr-2012  yamt sync with head
 1.42.2.1 19-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.45.14.3 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.45.14.2 21-Apr-2020  martin Sync with HEAD
 1.45.14.1 10-Jun-2019  christos Sync with HEAD
 1.45.12.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.63 07-Jun-2024  andvar s/concatentation/concatenation/ in comment.
 1.62 22-May-2020  christos fix reversed test.
 1.61 17-May-2020  christos No ACL support for install media (SMALLPROG)
 1.60 16-May-2020  christos Add ACL support for FFS. From FreeBSD.
 1.59 05-Mar-2016  uwe branches: 1.59.16;
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.
 1.58 04-Jan-2012  christos branches: 1.58.2; 1.58.20;
Add siginfo support from Daniel Loffgren.
 1.57 18-Aug-2011  manu branches: 1.57.2;
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
 1.56 03-Aug-2011  manu Make cp -p and mv preverve extended attributes, and complain if they cannot.

Also introduce library functions for copying extended attributes from one
file to another:
- extattr_copy_file, extattr_copy_fd, extattr_copy_link, with FreeBSD style,
where a namespace is to be supplied
- cpxattr, fcpxattr, lcpxattr, with Linux style, where all namespaces
accessible to the caller are copied, and the others are silently ignored.
 1.55 06-Feb-2011  darcy Add -l option to copy a tree as links.
Non-standard option similar to Gnutools cp(1)
Approved by core.
 1.54 21-Dec-2010  christos branches: 1.54.2;
Add -a archive flag. from Aleksey Cheusov
 1.53 08-Oct-2009  pooka 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
 1.52 29-Sep-2009  pooka 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.
 1.51 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
 1.50 26-May-2008  dholland Distinguish "this file failed" from "any file failed", to make cp -v
output behave itself. PR bin/37018 from Dieter Roelants.

(I used a slightly different patch to make sure "any file failed"
didn't get lost in the shuffle, and renamed the variables in the name
of greater clarity.)
 1.49 26-May-2008  christos PR/38755: murray armfield: /bin posix programs missing setprogname and/or
setlocale
 1.48 26-Dec-2006  alc branches: 1.48.10; 1.48.12;
fix whitespace nits (space -> tab)
 1.47 15-Oct-2006  christos c99 initializers
 1.46 15-Aug-2006  jschauma initialize dne variable in the beginning, then move the resetting of
this variable down into the second (ie post-order) pass to make cp
pass all regression tests again.
 1.45 15-Aug-2006  tron Avoid errors like "cp: /foo/bar/directory" exists if cp(1) is used to
copy multiple directories and the first one doesn't exist in the
target directiry but another one (e.g. the second) does.
 1.44 16-Jul-2006  jschauma branches: 1.44.2;
return functionality backed out yesterday after fixing the bug I had
introduced before. A regression test will be added to src/regress
shortly.
 1.43 15-Jul-2006  jschauma The last commit introduced a bug. Revert until that's found and fixed.
 1.42 15-Jul-2006  jschauma As suggested on tech-userlevel:
"-R" claims:
-R [...] Created directories have the same mode as the corre-
sponding source directory, unmodified
by the process' umask.

Make this actually true.

In addition, make '-P' (no symbolic links are followed) apply even if
'-R' is not specified. This allows users to overwrite symbolic links
with files and/or to copy symbolic links over a file without indirecting
through the link (ie a copy of a link turns the target into a link, not
a copy of the file pointed to by the source).
 1.41 17-Mar-2006  erh Fix Coverity issue 1754. Call fts_close() after we're done copying.
 1.40 16-Nov-2005  christos - Better detect pathname overflow (from FreeBSD)
- Change destination normal file detection to match with FreeBSD
- Trim trailing slashes from source filenames so that cp foo/ == cp foo
 1.39 24-Oct-2005  kleink Remove the "" -> "." target conversion kludge.
 1.38 15-Oct-2005  christos - Don't output 'src -> dst' when -v and there was an error.
- Mark usage as noreturn, and remove extraneous exit.
- Pass lint.
Reported by Liam Foy.
 1.37 15-Aug-2005  elad Add and document -N: When used with -p, it will not copy the file flags.
PR 13645.
 1.36 26-Jun-2005  christos sprinkle a little const, and now everything compiles with WARNS=3
 1.35 14-Sep-2003  jschauma Following private discussion with kleink@ and hubertf@ and public discussion
on tech-userlevel@, back out printescaped() functionality.
kleink: ``We sell rope.''
 1.34 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.33 04-Aug-2003  jschauma As discusses a little while back on tech-userlevel:

If stdout is a tty, use vis(3) to print any filenames to prevent garbage
from being printed if the filename contains control- or other non-printable
characters.

While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate.
 1.32 16-Dec-2002  jrf Added a -v verbose option to the cp(1) command. Updated man page and utils as well. This applies to PR bin/16834. This change was approved by Christos.
 1.31 13-Sep-2001  wiz ANSIfication and some KNF fixes by Petri Koistinen from bin/13681.
 1.30 07-Jul-2000  itojun errx?/warnx? audit. do not pass variable alone, use %s. idea from openbsd
 1.29 03-Jul-2000  matt include <stdlib.h>, <string.h>, or whatever as appropriate to shut up
gcc 2.96
 1.28 05-Sep-1999  kleink branches: 1.28.8;
Initialize locale on startup.
 1.27 01-Mar-1999  mjl Correct behaviour in case of dangling symlinks: they would be (contrary
to what the manpage and POSIX say) copied as symlinks, even without -R.
Return ENOENT instead. Closes PR 6975 by Johan Danielsson <joda@pdc.kth.se>.

From FreeBSD: return correct error message if source directory is
unreadable; remove unnecessarily included headers.
 1.26 25-Feb-1999  dean Got rid of redundant error message (X is a directory (not copied). was
printed twice)
 1.25 08-Oct-1998  wsanchez Fix bug where "cp -f" didn't work.
It's suppsed to remove the file and then copy, which it wasn't doing.
But no wait, it turns out that the described behaviour in the manual doesn't
agree with POSIX. So we change the above fix and the manual to "try copy, and
if fail, try remove, then copy".
Fix bug where "cp -R" didn't work on read-only directories:
It would make the directory, set the mode, and not be able to write files into it.
Don't bother mmap()ing files of zero length. Was a workaround for a bug in Rhapsody
mmap(), which didn't get along with such files, but makes sense anyway.
Fix race condition where "cp -p" would set the mod time of a file before close()ing
the file, which would update the mod time and therefore screw up the "-p" idea,
except, of course, while running in gdb, which sucked.
Add -f option to usage message in binary and man page. Already documented in man page.
 1.24 19-Aug-1998  thorpej Add some braces to keep egcs happy.
 1.23 28-Jul-1998  mycroft Be more retentive about use of NOTREACHED and noreturn.
 1.22 28-Jul-1998  mycroft Delint.
 1.21 28-Jul-1998  mycroft Delint.
 1.20 28-Jul-1998  mycroft Delint.
 1.19 14-Sep-1997  lukem * getopt returns -1 not EOF
* cleanup use of .Nm in manpage
 1.18 20-Jul-1997  thorpej - Use __COPYRIGHT() and __RCSID()
- Fix compiler warnings.
 1.17 21-May-1997  kleink Fix one remaining botch when copying directory trees using -R.
 1.16 19-May-1997  kleink Fix thinko in last commit, causing "cp file /" to succeed but
"cp file1 file2 /" to fail badly; fixes PR/3646 from Paul Kranenburg.
 1.15 09-Apr-1997  kleink Fix lossage with new namei() when the destination given is "/";
reported by Bernd Ernesti.
 1.14 07-Sep-1995  jtc Sync with 4.4lite2
 1.13 02-Apr-1995  mycroft Fix typo in S_FIFO case when copying recursively.
 1.12 21-Mar-1995  cgd convert to new RCS id conventions.
 1.11 26-Jan-1995  mycroft Fix core dump reported by Wolfram Schneider.
 1.10 22-Sep-1994  mycroft Merge 4.4-Lite version.
 1.9 28-Mar-1994  cgd no more MAP_FILE
 1.8 25-Feb-1994  jtc POSIX.2 (and common sense) says that you can't overwrite a directory with
a non-directory.
 1.7 09-Nov-1993  jtc Check user's response against both 'Y' and 'y' --- this is really supposed
to be a locale specific regular expression. This change hard codes POSIX
locale behavior, and will be replaced by a locale independant equivalent
as soon as locales are fully implemented.
 1.6 30-Oct-1993  mycroft From Lennart Augustsson:
If we mmap() the file, make sure we munmap() when we're done.
 1.5 07-Aug-1993  mycroft New version from uunet. Uses mmap().
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 07-Sep-1995  jtc imported from 44lite2
 1.1.1.2 22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.28.8.1 27-Jul-2000  itojun pullup (approved by releng-1-5)
printf-like format pedant. do not pass string variable alone. use "%s".
from openbsd.

/cvsroot/basesrc/bin/dd/conv.c 1.8 -> 1.9
/cvsroot/basesrc/bin/cp/cp.c 1.29 -> 1.30
/cvsroot/basesrc/bin/chmod/chmod.c 1.22 -> 1.23
 1.44.2.1 21-Aug-2006  ghen Pull up following revision(s) (requested by tron in ticket #30):
regress/bin/cp/cp.sh: revision 1.2
regress/bin/cp/cp.sh: revision 1.3
bin/cp/cp.c: revision 1.45
bin/cp/cp.c: revision 1.46
Avoid errors like "cp: /foo/bar/directory" exists if cp(1) is used to
copy multiple directories and the first one doesn't exist in the
target directiry but another one (e.g. the second) does.
initialize dne variable in the beginning, then move the resetting of
this variable down into the second (ie post-order) pass to make cp
pass all regression tests again.
allow each dir_to_dir test to be run individually without having to
rely on previous tests that set up the files and directories;
while here, clarify in each error message where exactly the error occurred
add a regression test for copying several subdirs into a target directory
where some subdirs already exist
 1.48.12.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.48.12.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.48.10.1 04-Jun-2008  yamt sync with head
 1.54.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.57.2.1 17-Apr-2012  yamt sync with head
 1.58.20.1 06-Mar-2016  martin Pull up following revision(s) (requested by uwe in ticket #1131):
bin/cp/cp.c: revision 1.59
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.
 1.58.2.1 27-Aug-2016  bouyer Pull up following revision(s) (requested by uwe in ticket #1372):
bin/cp/cp.c: revision 1.59
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.
 1.59.16.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.59.16.1 21-Apr-2020  martin Sync with HEAD
 1.5 07-Aug-1993  mycroft Clean up deleted files.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.18 16-May-2020  christos Add ACL support for FFS. From FreeBSD.
 1.17 04-Jan-2012  christos branches: 1.17.42;
Add siginfo support from Daniel Loffgren.
 1.16 06-Feb-2011  darcy branches: 1.16.4;
Add -l option to copy a tree as links.
Non-standard option similar to Gnutools cp(1)
Approved by core.
 1.15 16-Jul-2006  jschauma branches: 1.15.38;
return functionality backed out yesterday after fixing the bug I had
introduced before. A regression test will be added to src/regress
shortly.
 1.14 15-Jul-2006  jschauma The last commit introduced a bug. Revert until that's found and fixed.
 1.13 15-Jul-2006  jschauma As suggested on tech-userlevel:
"-R" claims:
-R [...] Created directories have the same mode as the corre-
sponding source directory, unmodified
by the process' umask.

Make this actually true.

In addition, make '-P' (no symbolic links are followed) apply even if
'-R' is not specified. This allows users to overwrite symbolic links
with files and/or to copy symbolic links over a file without indirecting
through the link (ie a copy of a link turns the target into a link, not
a copy of the file pointed to by the source).
 1.12 15-Oct-2005  christos - Don't output 'src -> dst' when -v and there was an error.
- Mark usage as noreturn, and remove extraneous exit.
- Pass lint.
Reported by Liam Foy.
 1.11 15-Aug-2005  elad Add and document -N: When used with -p, it will not copy the file flags.
PR 13645.
 1.10 26-Jun-2005  christos sprinkle a little const, and now everything compiles with WARNS=3
 1.9 14-Sep-2003  jschauma Following private discussion with kleink@ and hubertf@ and public discussion
on tech-userlevel@, back out printescaped() functionality.
kleink: ``We sell rope.''
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.7 04-Aug-2003  jschauma As discusses a little while back on tech-userlevel:

If stdout is a tty, use vis(3) to print any filenames to prevent garbage
from being printed if the filename contains control- or other non-printable
characters.

While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate.
 1.6 13-Sep-2001  wiz ANSIfication and some KNF fixes by Petri Koistinen from bin/13681.
 1.5 08-Oct-1998  wsanchez Fix bug where "cp -f" didn't work.
It's suppsed to remove the file and then copy, which it wasn't doing.
But no wait, it turns out that the described behaviour in the manual doesn't
agree with POSIX. So we change the above fix and the manual to "try copy, and
if fail, try remove, then copy".
Fix bug where "cp -R" didn't work on read-only directories:
It would make the directory, set the mode, and not be able to write files into it.
Don't bother mmap()ing files of zero length. Was a workaround for a bug in Rhapsody
mmap(), which didn't get along with such files, but makes sense anyway.
Fix race condition where "cp -p" would set the mod time of a file before close()ing
the file, which would update the mod time and therefore screw up the "-p" idea,
except, of course, while running in gdb, which sucked.
Add -f option to usage message in binary and man page. Already documented in man page.
 1.4 28-Jul-1998  mycroft Delint.
 1.3 21-Mar-1995  cgd convert to new RCS id conventions.
 1.2 22-Sep-1994  mycroft Merge 4.4-Lite version.
 1.1 07-Aug-1993  mycroft branches: 1.1.1;
New version from uunet. Uses mmap().
 1.1.1.1 22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.15.38.1 08-Feb-2011  bouyer Sync with HEAD
 1.16.4.1 17-Apr-2012  yamt sync with head
 1.17.42.2 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.17.42.1 21-Apr-2020  martin Sync with HEAD
 1.6 22-Sep-1994  mycroft Clean up deleted files.
 1.5 07-Aug-1993  mycroft New version from uunet. Uses mmap().
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.50 15-Jan-2024  christos PR/57857: Ricardo Branco: Always copy regular files, even if they appear to
be zero-sized.
 1.49 17-May-2020  christos branches: 1.49.6;
No ACL support for install media (SMALLPROG)
 1.48 16-May-2020  christos Add ACL support for FFS. From FreeBSD.
 1.47 23-Sep-2019  christos PR/54564: Jan Schaumann: cp of a fifo yields an empty file
Don't short-circuit 0 sized stat entries if they don't belong to regular files.
Also don't try to mmap non-regular files.
 1.46 17-Jul-2018  darcy branches: 1.46.2;
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.
 1.45 29-Feb-2016  mrg branches: 1.45.14; 1.45.16;
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.
 1.44 03-Mar-2015  enami Fix the name of failed function in warning message.
 1.43 02-Mar-2015  enami Don't truncate at microseconds while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html
 1.42 11-Dec-2013  dholland branches: 1.42.4; 1.42.6;
Remove entirely bogus /* NOTREACHED */ annotation.
 1.41 04-Jan-2012  christos branches: 1.41.6;
Add siginfo support from Daniel Loffgren.
 1.40 03-Aug-2011  manu branches: 1.40.2;
Make cp -p and mv preverve extended attributes, and complain if they cannot.

Also introduce library functions for copying extended attributes from one
file to another:
- extattr_copy_file, extattr_copy_fd, extattr_copy_link, with FreeBSD style,
where a namespace is to be supplied
- cpxattr, fcpxattr, lcpxattr, with Linux style, where all namespaces
accessible to the caller are copied, and the others are silently ignored.
 1.39 06-Feb-2011  darcy Add -l option to copy a tree as links.
Non-standard option similar to Gnutools cp(1)
Approved by core.
 1.38 04-Jan-2011  wiz branches: 1.38.2;
Fix fd leak in error case. Found by cppcheck.
 1.37 21-Dec-2010  christos Add -a archive flag. from Aleksey Cheusov
 1.36 25-Oct-2010  tron Re-enable support for reading files 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.
 1.35 22-Oct-2010  pooka 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)
 1.34 26-Oct-2007  hira Add -N to usage.
 1.33 25-Oct-2007  jld Touching up the permissions to preserve set-ID bits is appropriate
only in the case where the destination did not previously exist, and
necessary only when -p isn't given.

Closes PR bin/30188.
 1.32 16-Jul-2006  jschauma branches: 1.32.10;
return functionality backed out yesterday after fixing the bug I had
introduced before. A regression test will be added to src/regress
shortly.
 1.31 15-Jul-2006  jschauma The last commit introduced a bug. Revert until that's found and fixed.
 1.30 15-Jul-2006  jschauma As suggested on tech-userlevel:
"-R" claims:
-R [...] Created directories have the same mode as the corre-
sponding source directory, unmodified
by the process' umask.

Make this actually true.

In addition, make '-P' (no symbolic links are followed) apply even if
'-R' is not specified. This allows users to overwrite symbolic links
with files and/or to copy symbolic links over a file without indirecting
through the link (ie a copy of a link turns the target into a link, not
a copy of the file pointed to by the source).
 1.29 15-Oct-2005  christos - Don't output 'src -> dst' when -v and there was an error.
- Mark usage as noreturn, and remove extraneous exit.
- Pass lint.
Reported by Liam Foy.
 1.28 15-Aug-2005  elad Add and document -N: When used with -p, it will not copy the file flags.
PR 13645.
 1.27 04-Jan-2004  jschauma remove unused code left from printescaped() backput as pointed out by Jeff
Ito in PR bin/23969 and PR bin/23970.
 1.26 14-Sep-2003  jschauma Following private discussion with kleink@ and hubertf@ and public discussion
on tech-userlevel@, back out printescaped() functionality.
kleink: ``We sell rope.''
 1.25 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.24 04-Aug-2003  jschauma As discusses a little while back on tech-userlevel:

If stdout is a tty, use vis(3) to print any filenames to prevent garbage
from being printed if the filename contains control- or other non-printable
characters.

While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate.
 1.23 20-Jan-2003  simonb The Double-Semi-Colon Police.
 1.22 16-Dec-2002  jrf Added a -v verbose option to the cp(1) command. Updated man page and utils as well. This applies to PR bin/16834. This change was approved by Christos.
 1.21 19-Oct-2002  provos use readlink with bufsize - 1; approved thorpej.
 1.20 13-Sep-2001  wiz ANSIfication and some KNF fixes by Petri Koistinen from bin/13681.
 1.19 30-Aug-2001  chs enable use of mmap(), falling back to read()/write() if mmap() fails.
 1.18 18-Jul-2001  tron Use madvise(2) after mmap(2) in case "VM_AND_BUFFER_CACHE_SYNCHRONIZED"
is defined which it is not right now.
 1.17 01-Mar-1999  mjl Correct behaviour in case of dangling symlinks: they would be (contrary
to what the manpage and POSIX say) copied as symlinks, even without -R.
Return ENOENT instead. Closes PR 6975 by Johan Danielsson <joda@pdc.kth.se>.

From FreeBSD: return correct error message if source directory is
unreadable; remove unnecessarily included headers.
 1.16 08-Oct-1998  wsanchez Fix bug where "cp -f" didn't work.
It's suppsed to remove the file and then copy, which it wasn't doing.
But no wait, it turns out that the described behaviour in the manual doesn't
agree with POSIX. So we change the above fix and the manual to "try copy, and
if fail, try remove, then copy".
Fix bug where "cp -R" didn't work on read-only directories:
It would make the directory, set the mode, and not be able to write files into it.
Don't bother mmap()ing files of zero length. Was a workaround for a bug in Rhapsody
mmap(), which didn't get along with such files, but makes sense anyway.
Fix race condition where "cp -p" would set the mod time of a file before close()ing
the file, which would update the mod time and therefore screw up the "-p" idea,
except, of course, while running in gdb, which sucked.
Add -f option to usage message in binary and man page. Already documented in man page.
 1.15 19-Aug-1998  thorpej Add some braces to keep egcs happy.
 1.14 28-Jul-1998  mycroft Delint.
 1.13 28-Jul-1998  mycroft Delint.
 1.12 20-Feb-1998  mycroft Nit: Use MAP_SHARED for read-only mappings where appropriate.
 1.11 17-Feb-1998  augustss Use MAP_PRIVATE|MAP_FILE instead of 0 in mmap().
 1.10 19-Oct-1997  mycroft Use futimes(2) if possible. Also correct an error message.
 1.9 19-Oct-1997  enami Preserve owner/group/mode/atime/mtime of symlink if -p flag is given.
 1.8 20-Jul-1997  thorpej - Use __COPYRIGHT() and __RCSID()
- Fix compiler warnings.
 1.7 15-May-1997  mikel add missing close-brackets; from Greg Oster in PR bin/3613.
 1.6 26-Feb-1997  cgd Patch from BSDI (via Keith Bostic):
>NFS doesn't support chflags; ignore errors unless there's reason
>to believe we're losing bits. (Note, this still won't be right
>if the server supports flags and we were trying to *remove* flags
>on a file that we copied, i.e., that we didn't create.)
 1.5 09-Jan-1997  tls kill use of register
 1.4 02-Aug-1995  jtc Don't remove the destination file if there is a write error. This is
very bad if it is actually a device or fifo. POSIX.2 requires that a
diagnostic message be written, the file descriptor be closed, and for
cp to continue on with the rest of the files.
 1.3 21-Mar-1995  cgd convert to new RCS id conventions.
 1.2 22-Sep-1994  mycroft Merge 4.4-Lite version.
 1.1 22-Sep-1994  mycroft branches: 1.1.1;
Initial revision
 1.1.1.1 22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.32.10.1 06-Nov-2007  matt sync with HEAD
 1.38.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.40.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.40.2.1 17-Apr-2012  yamt sync with head
 1.41.6.1 19-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.42.6.1 03-Mar-2016  martin Pull up following revision(s) (requested by nakayama in ticket #1096):
bin/mv/mv.c: revision 1.44
bin/cp/utils.c: revision 1.43-1.44
lib/librumphijack/hijack.c: revision 1.112-1.115
usr.bin/touch/touch.c: revision 1.33
sbin/restore/tape.c: revision 1.68
sbin/restore/dirs.c: revision 1.51
Don't truncate at sub-microsecond while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html

Fix the name of failed function in warning message.

Hijack utimensat(2) so that t_vfs test passes after cp(1)/mv(1) are
changed to use the system call. Linux also has this system call, but
not tested this on linux.

Also hijack futimens(2) so that t_sh test passes.

Define a generic ATCALL() and use it to implement utimensat()
Make ATCALL() behave for absolute paths too.
 1.42.4.2 06-Mar-2016  martin Pull up following revision(s) (requested by mrg in ticket #1130):
bin/cp/utils.c: revision 1.45
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.
 1.42.4.1 03-Mar-2016  martin Pull up following revision(s) (requested by nakayama in ticket #1096):
bin/mv/mv.c: revision 1.44
bin/cp/utils.c: revision 1.43-1.44
lib/librumphijack/hijack.c: revision 1.112-1.115
usr.bin/touch/touch.c: revision 1.33
sbin/restore/tape.c: revision 1.68
sbin/restore/dirs.c: revision 1.51
Don't truncate at sub-microsecond while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html

Fix the name of failed function in warning message.

Hijack utimensat(2) so that t_vfs test passes after cp(1)/mv(1) are
changed to use the system call. Linux also has this system call, but
not tested this on linux.

Also hijack futimens(2) so that t_sh test passes.

Define a generic ATCALL() and use it to implement utimensat()
Make ATCALL() behave for absolute paths too.
 1.45.16.4 21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.45.16.3 21-Apr-2020  martin Sync with HEAD
 1.45.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.45.16.1 10-Jun-2019  christos Sync with HEAD
 1.45.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.46.2.1 23-Sep-2021  martin Pull up following revision(s) (requested by skrll in ticket #1348):

bin/cp/utils.c: revision 1.47

PR/54564: Jan Schaumann: cp of a fifo yields an empty file

Don't short-circuit 0 sized stat entries if they don't belong to regular
files.

Also don't try to mmap non-regular files.
 1.49.6.1 20-Jul-2024  martin Pull up following revision(s) (requested by rin in ticket #742):

bin/cp/utils.c: revision 1.50

PR/57857: Ricardo Branco: Always copy regular files, even if they appear to
be zero-sized.

RSS XML Feed