Bug 88056 - [patch] [request] cp(1) could really use Linux's -x option (stay on this file system)
Summary: [patch] [request] cp(1) could really use Linux's -x option (stay on this file...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: Gavin Atkinson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-26 21:20 UTC by Mike Silbersack
Modified: 2010-03-14 16:10 UTC (History)
0 users

See Also:


Attachments
cp.c.patch (949 bytes, patch)
2006-05-31 22:27 UTC, leeg
no flags Details | Diff
utils.c.patch (506 bytes, patch)
2006-05-31 22:27 UTC, leeg
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Silbersack 2005-10-26 21:20:20 UTC
I was cloning a machine when I noticed that we don't have -x, meaning
that I had to be very careful when copying the / filesystem.  If we
had -x, that would be much simpler to do.
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2005-10-26 23:10:33 UTC
State Changed
From-To: open->suspended

Mark suspended awaiting patches from someone with an interest.
Comment 2 leeg 2006-05-31 22:27:50 UTC
I've only tried this on Darwin/BSD but it appears to work...adds a '-x' 
flag which sets the FTS_XDEV option.

Cheers,
Graham.
-- 
Graham Lee
UNIX Systems Manager,
Oxford Physics Practical Course
http://users.ox.ac.uk/~wadh1342
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2006-06-03 20:05:06 UTC
State Changed
From-To: suspended->open

leeg@teaching.physics.ox.ac.uk has provided a patch.
Comment 4 Gavin Atkinson freebsd_committer freebsd_triage 2010-01-16 21:19:28 UTC
Responsible Changed
From-To: freebsd-bugs->gavin

Mine
Comment 5 dfilter service freebsd_committer 2010-01-17 09:37:43 UTC
Author: gavin
Date: Sun Jan 17 09:37:31 2010
New Revision: 202461
URL: http://svn.freebsd.org/changeset/base/202461

Log:
  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

Modified:
  head/bin/cp/cp.1
  head/bin/cp/cp.c
  head/bin/cp/utils.c

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

Modified: head/bin/cp/cp.c
==============================================================================
--- head/bin/cp/cp.c	Sun Jan 17 08:41:07 2010	(r202460)
+++ head/bin/cp/cp.c	Sun Jan 17 09:37:31 2010	(r202461)
@@ -101,8 +101,9 @@ main(int argc, char *argv[])
 	int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash;
 	char *target;
 
+	fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
 	Hflag = Lflag = Pflag = 0;
-	while ((ch = getopt(argc, argv, "HLPRafilnprv")) != -1)
+	while ((ch = getopt(argc, argv, "HLPRafilnprvx")) != -1)
 		switch (ch) {
 		case 'H':
 			Hflag = 1;
@@ -150,6 +151,9 @@ main(int argc, char *argv[])
 		case 'v':
 			vflag = 1;
 			break;
+		case 'x':
+			fts_options |= FTS_XDEV;
+			break;
 		default:
 			usage();
 			break;
@@ -160,7 +164,6 @@ main(int argc, char *argv[])
 	if (argc < 2)
 		usage();
 
-	fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
 	if (Rflag && rflag)
 		errx(1, "the -R and -r options may not be specified together");
 	if (rflag)

Modified: head/bin/cp/utils.c
==============================================================================
--- head/bin/cp/utils.c	Sun Jan 17 08:41:07 2010	(r202460)
+++ head/bin/cp/utils.c	Sun Jan 17 09:37:31 2010	(r202461)
@@ -518,8 +518,8 @@ usage(void)
 {
 
 	(void)fprintf(stderr, "%s\n%s\n",
-"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file target_file",
-"       cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file ... "
+"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file target_file",
+"       cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file ... "
 "target_directory");
 	exit(EX_USAGE);
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 6 Gavin Atkinson freebsd_committer freebsd_triage 2010-01-17 09:41:12 UTC
State Changed
From-To: open->patched

Patched, will merge in 1 month
Comment 7 dfilter service freebsd_committer 2010-02-16 22:20:13 UTC
Author: gavin
Date: Tue Feb 16 22:19:55 2010
New Revision: 203975
URL: http://svn.freebsd.org/changeset/base/203975

Log:
  Merge r202461 from head:
  
    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.
  
  PR:		bin/88056
  Initial patch by: Graham J Lee   leeg teaching.physics.ox.ac.uk

Modified:
  stable/8/bin/cp/cp.1
  stable/8/bin/cp/cp.c
  stable/8/bin/cp/utils.c
Directory Properties:
  stable/8/bin/cp/   (props changed)

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

Modified: stable/8/bin/cp/cp.c
==============================================================================
--- stable/8/bin/cp/cp.c	Tue Feb 16 21:59:17 2010	(r203974)
+++ stable/8/bin/cp/cp.c	Tue Feb 16 22:19:55 2010	(r203975)
@@ -101,8 +101,9 @@ main(int argc, char *argv[])
 	int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash;
 	char *target;
 
+	fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
 	Hflag = Lflag = Pflag = 0;
-	while ((ch = getopt(argc, argv, "HLPRafilnprv")) != -1)
+	while ((ch = getopt(argc, argv, "HLPRafilnprvx")) != -1)
 		switch (ch) {
 		case 'H':
 			Hflag = 1;
@@ -150,6 +151,9 @@ main(int argc, char *argv[])
 		case 'v':
 			vflag = 1;
 			break;
+		case 'x':
+			fts_options |= FTS_XDEV;
+			break;
 		default:
 			usage();
 			break;
@@ -160,7 +164,6 @@ main(int argc, char *argv[])
 	if (argc < 2)
 		usage();
 
-	fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
 	if (Rflag && rflag)
 		errx(1, "the -R and -r options may not be specified together");
 	if (rflag)

Modified: stable/8/bin/cp/utils.c
==============================================================================
--- stable/8/bin/cp/utils.c	Tue Feb 16 21:59:17 2010	(r203974)
+++ stable/8/bin/cp/utils.c	Tue Feb 16 22:19:55 2010	(r203975)
@@ -518,8 +518,8 @@ usage(void)
 {
 
 	(void)fprintf(stderr, "%s\n%s\n",
-"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file target_file",
-"       cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file ... "
+"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file target_file",
+"       cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file ... "
 "target_directory");
 	exit(EX_USAGE);
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 8 Gavin Atkinson freebsd_committer freebsd_triage 2010-03-14 16:03:52 UTC
State Changed
From-To: patched->closed

Committed to head, nad merged to stable/8 and stable/7.  Thanks for your bug 
report and patch!
Comment 9 dfilter service freebsd_committer 2010-03-14 16:03:55 UTC
Author: gavin
Date: Sun Mar 14 16:03:36 2010
New Revision: 205156
URL: http://svn.freebsd.org/changeset/base/205156

Log:
  Merge r202461 from head:
  
    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.
  
  PR:		bin/88056
  Initial patch by: Graham J Lee  <leeg teaching.physics.ox.ac.uk>

Modified:
  stable/7/bin/cp/cp.1
  stable/7/bin/cp/cp.c
  stable/7/bin/cp/utils.c
Directory Properties:
  stable/7/bin/cp/   (props changed)

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

Modified: stable/7/bin/cp/cp.c
==============================================================================
--- stable/7/bin/cp/cp.c	Sun Mar 14 15:49:04 2010	(r205155)
+++ stable/7/bin/cp/cp.c	Sun Mar 14 16:03:36 2010	(r205156)
@@ -101,8 +101,9 @@ main(int argc, char *argv[])
 	int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash;
 	char *target;
 
+	fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
 	Hflag = Lflag = Pflag = 0;
-	while ((ch = getopt(argc, argv, "HLPRafilnprv")) != -1)
+	while ((ch = getopt(argc, argv, "HLPRafilnprvx")) != -1)
 		switch (ch) {
 		case 'H':
 			Hflag = 1;
@@ -150,6 +151,9 @@ main(int argc, char *argv[])
 		case 'v':
 			vflag = 1;
 			break;
+		case 'x':
+			fts_options |= FTS_XDEV;
+			break;
 		default:
 			usage();
 			break;
@@ -160,7 +164,6 @@ main(int argc, char *argv[])
 	if (argc < 2)
 		usage();
 
-	fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
 	if (Rflag && rflag)
 		errx(1, "the -R and -r options may not be specified together");
 	if (rflag)

Modified: stable/7/bin/cp/utils.c
==============================================================================
--- stable/7/bin/cp/utils.c	Sun Mar 14 15:49:04 2010	(r205155)
+++ stable/7/bin/cp/utils.c	Sun Mar 14 16:03:36 2010	(r205156)
@@ -429,8 +429,8 @@ usage(void)
 {
 
 	(void)fprintf(stderr, "%s\n%s\n",
-"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file target_file",
-"       cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file ... "
+"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file target_file",
+"       cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file ... "
 "target_directory");
 	exit(EX_USAGE);
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"