Implement an "-x" option to cp(1), for compatibility with Linux and

feature parity with du(1) and similar:  When set, cp(1) will not traverse
mount points.

Initial patch by:       Graham J Lee   leeg teaching.physics.ox.ac.uk

PR:		bin/88056
Initial patch by: Graham J Lee   leeg teaching.physics.ox.ac.uk
Approved by:	ed (mentor)
MFC after:	1 month
This commit is contained in:
Gavin Atkinson 2010-01-17 09:37:31 +00:00
parent 6c1e384c63
commit f815125fbc
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=202461
3 changed files with 12 additions and 7 deletions

View File

@ -32,7 +32,7 @@
.\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" @(#)cp.1 8.3 (Berkeley) 4/18/94
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd October 27, 2006 .Dd January 17, 2010
.Dt CP 1 .Dt CP 1
.Os .Os
.Sh NAME .Sh NAME
@ -45,7 +45,7 @@
.Op Fl H | Fl L | Fl P .Op Fl H | Fl L | Fl P
.Oc .Oc
.Op Fl f | i | n .Op Fl f | i | n
.Op Fl alpv .Op Fl alpvx
.Ar source_file target_file .Ar source_file target_file
.Nm .Nm
.Oo .Oo
@ -53,7 +53,7 @@
.Op Fl H | Fl L | Fl P .Op Fl H | Fl L | Fl P
.Oc .Oc
.Op Fl f | i | n .Op Fl f | i | n
.Op Fl alpv .Op Fl alpvx
.Ar source_file ... target_directory .Ar source_file ... target_directory
.Sh DESCRIPTION .Sh DESCRIPTION
In the first synopsis form, the In the first synopsis form, the
@ -183,6 +183,8 @@ permissions.
Cause Cause
.Nm .Nm
to be verbose, showing files as they are copied. to be verbose, showing files as they are copied.
.It Fl x
File system mount points are not traversed.
.El .El
.Pp .Pp
For each destination file that already exists, its contents are For each destination file that already exists, its contents are

View File

@ -101,8 +101,9 @@ main(int argc, char *argv[])
int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash; int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash;
char *target; char *target;
fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
Hflag = Lflag = Pflag = 0; Hflag = Lflag = Pflag = 0;
while ((ch = getopt(argc, argv, "HLPRafilnprv")) != -1) while ((ch = getopt(argc, argv, "HLPRafilnprvx")) != -1)
switch (ch) { switch (ch) {
case 'H': case 'H':
Hflag = 1; Hflag = 1;
@ -150,6 +151,9 @@ main(int argc, char *argv[])
case 'v': case 'v':
vflag = 1; vflag = 1;
break; break;
case 'x':
fts_options |= FTS_XDEV;
break;
default: default:
usage(); usage();
break; break;
@ -160,7 +164,6 @@ main(int argc, char *argv[])
if (argc < 2) if (argc < 2)
usage(); usage();
fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
if (Rflag && rflag) if (Rflag && rflag)
errx(1, "the -R and -r options may not be specified together"); errx(1, "the -R and -r options may not be specified together");
if (rflag) if (rflag)

View File

@ -518,8 +518,8 @@ usage(void)
{ {
(void)fprintf(stderr, "%s\n%s\n", (void)fprintf(stderr, "%s\n%s\n",
"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file target_file", "usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file target_file",
" cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file ... " " cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file ... "
"target_directory"); "target_directory");
exit(EX_USAGE); exit(EX_USAGE);
} }